[Subscribe(Standard.Paragraph.Saved)] public class SaveSubscriber : NotificationSubscriber { public override void OnNotify(string notification, NotificationArgs args) { if (args == null || !(args is Standard.Paragraph.ParagraphNotificationArgs)) { return; } var pArgs = (Standard.Paragraph.ParagraphNotificationArgs)args; if (pArgs.Target.ModuleSystemName.ToLower().Equals("DWCMSModule")) { pArgs.Target.ModuleProperties.set_Value("test", "1234"); } base.OnNotify(notification, args); } }
Developer forum
E-mail notifications
Module property in notificationsubscriber
Keld Gøtterup
Posted on 25/05/2011 10:06:39
Im trying to use notification subscriber to create an extra module property to be used on the edit and frontend, but it doesn't seem to register it
i do hope someone can see where im at fault.
Replies
Nicolai Høeg Pedersen
Posted on 25/05/2011 10:14:55
This post has been marked as an answer
Think there is a little glitch in the API:
So you have to do this - and save the paragraph again since .Saved notification is raised after the paragraph is saved to database.
And you do not need the base.OnNotify line.
So you have to do this - and save the paragraph again since .Saved notification is raised after the paragraph is saved to database.
pArgs.Target.ModuleProperties.set_Value("test", "1234"); pArgs.Target.ModuleSettings = pArgs.Target.ModuleProperties.toString(); pArgs.Target.Save();
Votes for this answer: 0
Keld Gøtterup
Posted on 25/05/2011 10:48:03
[Subscribe(Standard.Paragraph.Saved)] public class SaveSubscriber : NotificationSubscriber { public override void OnNotify(string notification, NotificationArgs args) { if (args == null || !(args is Standard.Paragraph.ParagraphNotificationArgs)) { return; } var pArgs = (Standard.Paragraph.ParagraphNotificationArgs)args; if (pArgs.Target.ModuleSystemName.ToLower().Equals("DWCMSModule")) { pArgs.Target.ModuleProperties.set_Value("test", "1234"); pArgs.Target.ModuleSettings = pArgs.Target.ModuleProperties.ToString(); pArgs.Target.Save(); } } }
Nicolai Høeg Pedersen
Posted on 25/05/2011 11:03:26
Just to make sure - you are using the DW 7 interface - the one with the blue ribbon?
Morten Bengtson
Posted on 25/05/2011 11:15:10
Maybe this line could be the problem...
Lower case or not?
/Morten
if (pArgs.Target.ModuleSystemName.ToLower().Equals("DWCMSModule"))
Lower case or not?
/Morten
Nicolai Høeg Pedersen
Posted on 25/05/2011 11:32:19
The problem is the getter on paragraph.moduleproperties...
So do like this:
So do like this:
Dim theProperties As Properties = Me.ModuleProperties theProperties.Value("test") = "1234" Me.ModuleSettings = theProperties.ToString()
Keld Gøtterup
Posted on 25/05/2011 11:39:27
Maybe this line could be the problem...
1if
(pArgs.Target.ModuleSystemName.ToLower().Equals(
"DWCMSModule"
))
Lower case or not?
/Morten
Yes that is obviously(for other people than me) a problem and is now changed.
But now im being logged out of the system when saving :s
Keld Gøtterup
Posted on 25/05/2011 11:49:24
but it does save the property now
Keld Gøtterup
Posted on 25/05/2011 11:56:00
It seems that the makes it run in an infinite loop so i have to make some tests to see if the value have been changed and only save when that is the case.
pArgs.Target.Save();
Thank you both for the help.
Morten Bengtson
Posted on 25/05/2011 12:50:10
To prevent the infinite loop, you can add a few lines to the beginning of your OnNotify...
if (HttpContext.Current.Items.Contains(notification)) return; HttpContext.Current.Items.Add(notification, true);
You must be logged in to post in the forum