Custom Module event handlers

Posted by Community Admin on 04-Aug-2018 01:33

Custom Module event handlers

All Replies

Posted by Community Admin on 13-Feb-2013 00:00

I have created a custom module (using module builder). Can you please explain to me how I can capture the events that are fired during item creation (or for that matter item deletion/update as well)? For example, I have a custom module is called 'Projects'. It's content type is of type 'Project'. In the admin interface, I would like to intercept the 'Create a Project' event in order to add code that will send email notifications to a group of people. Surely this must be possible. Looking at the 'code reference' for this module, there are no real examples of performing this task...

This seems to be a good case for 'Workflow' where you can add any custom code/business process-- but there doesn't seem to be any custom types of workflow that you can attach (they're all pre-configured for approval processes...)

Greatly appreciated.

 

Posted by Community Admin on 13-Feb-2013 00:00

Great! thanks for the response. Do you happen to have any code samples on how to implement these methods? I've used the following as a baseline example and have it all working as this example, but am a bit unsure as to how to override the actual methods I'm interested in (capturing the create/edit events as opposed to the 'published' event)...

www.sitefinity.com/.../overwriting-the-default-lifecycledecorator-for-a-content-manager

Posted by Community Admin on 15-Feb-2013 00:00

I'm just posting to follow up to my own post as I resolved my own issue. By following the example of the previous KB article I simply had to do the following (which appears to work). In the 'ExecuteOnPublish' method, simply subscribe to the events you're interested in there -- and then create the handler methods to do the custom tasks (after contentCreation/contentUpdate).

protected override ILifecycleDataItemGeneric ExecuteOnPublish(ILifecycleDataItemGeneric masterItem, ILifecycleDataItemGeneric liveItem, System.Globalization.CultureInfo culture = null, DateTime? publicationDate = null)
       
            ILifecycleDataItemGeneric i = base.ExecuteOnPublish(masterItem, liveItem, culture, publicationDate);

            EventHub.Subscribe<IDynamicContentCreatedEvent>(evt => ContentCreatedEventHandler(evt));
            EventHub.Subscribe<IDynamicContentUpdatedEvent>(evt => ContentUpdatedEventHandler(evt));

         return i;


Thanks for pointing me to the proper methods Steve (I just needed a bit more understanding on where exactly to subscribe to these events)...

This thread is closed