Developer forum

Forum » Development » Module property in notificationsubscriber

Module property in notificationsubscriber

Keld Gøtterup
Reply
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
[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);
        }


    }
i do hope someone can see where im at fault.

Replies

 
Nicolai Høeg Pedersen
Reply
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.
pArgs.Target.ModuleProperties.set_Value("test", "1234");
pArgs.Target.ModuleSettings = pArgs.Target.ModuleProperties.toString();
pArgs.Target.Save();
And you do not need the base.OnNotify line.
Votes for this answer: 0
 
Keld Gøtterup
Reply
 
  [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(); 
            }
        }

    }
Now it looks like this but it still doesn't seem to work.
 
Nicolai Høeg Pedersen
Reply
Just to make sure - you are using the DW 7 interface - the one with the blue ribbon?
 
Morten Bengtson
Reply
Maybe this line could be the problem...

if (pArgs.Target.ModuleSystemName.ToLower().Equals("DWCMSModule"))

Lower case or not?

/Morten
 
Nicolai Høeg Pedersen
Reply
The problem is the getter on paragraph.moduleproperties...

So do like this:
Dim theProperties As Properties = Me.ModuleProperties
theProperties.Value("test") = "1234"
Me.ModuleSettings = theProperties.ToString()


 
Keld Gøtterup
Reply
Maybe this line could be the problem...

1
if (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
Reply

but it does save the property now
 
Keld Gøtterup
Reply

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
Reply
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