Developer forum

Forum » Development » how do i read paragraphModuleSetting xml before deleting a paragraph

how do i read paragraphModuleSetting xml before deleting a paragraph

Jacob Jensen
Reply

Hi.

I have a custom module, thats enabled in search.

I need to tricker an event, set a boolean to false in custom table if the user deletes a paragraph with my custom module in it. So the row wont still be enabled in search.

In other words, how do i read paragraphModuleSetting xml before deleting a paragraph ?

Anyone can help me out ?

Best regards
/Jacob

Edit: I need to check if a user deletes a page with a paragrafh containing my custommodule to.


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Jacob,

 

I would recommend to implement a notification subscriber that listens for the Dynamicweb.Notifications.Standard.Paragraph.Deleted notification. This is called every time a paragraph is deleted. To determine whether your custom module is attached on the paragraph, you can check the Target property of the argument of the notification.

 

Like this:

namespace ParagraphDeletedObserver
{
    [Dynamicweb.Extensibility.Subscribe(Dynamicweb.Notifications.Standard.Paragraph.Deleted)]
    public class ParagraphDeletedObserver : Dynamicweb.Extensibility.NotificationSubscriber
    {
        internal const string CustomModuleSystemName = "MyCustomModuleSystemName";

        public override void OnNotify(string notification, Dynamicweb.Extensibility.NotificationArgs args)
        {
            // Cast to proper argument type
            var myArgs = (Dynamicweb.Notifications.Standard.Paragraph.ParagraphNotificationArgs)args;

            // Check whether the Custom Module is attached to the deleted paragraph
            // myArgs.Target is the Paragraph object being deleted
            if (myArgs.Target.ModuleSystemName.Equals(CustomModuleSystemName, System.StringComparison.InvariantCultureIgnoreCase))
            {
                ChangeSearchSettings(myArgs.Target);
            }
        }

        internal static void ChangeSearchSettings(Dynamicweb.Content.Paragraph p)
        {
            // Implement code to change the boolean value in search
        }
    }

    [Dynamicweb.Extensibility.Subscribe(Dynamicweb.Notifications.Standard.Page.Deleted)]
    public class PageDeletedObserver : Dynamicweb.Extensibility.NotificationSubscriber
    {
        public override void OnNotify(string notification, Dynamicweb.Extensibility.NotificationArgs args)
        {
            // Cast to proper argument type
            var myArgs = (Dynamicweb.Notifications.Standard.Page.PageNotificationArgs)args;

            // Check whether a paragraph on this page has the Custom Module attached
            foreach (Dynamicweb.Content.Paragraph p in Dynamicweb.Content.Paragraph.GetParagraphsByPageID(myArgs.Target.ID))
            {
                if (p.ModuleSystemName.Equals(ParagraphDeletedObserver.CustomModuleSystemName, System.StringComparison.InvariantCultureIgnoreCase))
                {
                    ParagraphDeletedObserver.ChangeSearchSettings(p);
                }
            }
        }
    }
}

 

Hope this gives you some inspiration :)

 

- Jeppe

 
Jacob Jensen
Reply

Hi Jeppe.

Thx, but i think iam doing something wrong, its like the the OnNotify is never envoked. - But it looks like ur "inspiration code", is the perfect approach, thx.

Iwe attached an image, showing my vs.net setup. Iwe tried set at breakpoint in another method in my customModule and it is caught by visual studio, but none of the breakpoints is caught from the shown code in the attachment, can u see what iam doing wrong ?

Best regards
Jacob

 

dw-support.png
 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

I just tested it locally, and it seems that there is indeed an issue with these notifications not being fired as expected. I will investigate further and get back to you.

 
Jacob Jensen
Reply

Thx alot, iam using the latest "stable" version if it has anything to do with the problem, the customer is using 8.2.2.1

Best regards

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Jacob,

 

Sorry for the radio silence. The issue was caused by the two notification never actually being fired. This has been fixed in bug 12049 and will be out with 8.2.3.0 which we plan to release today.

 

- Jeppe

 

You must be logged in to post in the forum