More in this section

Forums / Developing with Sitefinity / Custom Module event handlers

Custom Module event handlers

4 posts, 1 answered
  1. Rico
    Rico avatar
    88 posts
    Registered:
    30 Aug 2012
    13 Feb 2013
    Link to this post

    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.

     

  2. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    Answered
  3. Rico
    Rico avatar
    88 posts
    Registered:
    30 Aug 2012
    13 Feb 2013 in reply to Steve
    Link to this post

    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)...

    http://www.sitefinity.com/developer-network/knowledge-base/overwriting-the-default-lifecycledecorator-for-a-content-manager

  4. Rico
    Rico avatar
    88 posts
    Registered:
    30 Aug 2012
    15 Feb 2013 in reply to Rico
    Link to this post

    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)...

4 posts, 1 answered