ModuleBuilder - Events (such as OnCreate or OnUpdate)

Posted by Community Admin on 04-Aug-2018 13:16

ModuleBuilder - Events (such as OnCreate or OnUpdate)

All Replies

Posted by Community Admin on 22-Apr-2014 00:00

I have written a module using the Module Builder.  It has a Content Type called "Slide".  I have written a widget that creates a slideshow for a homepage using a jQuery script to loop through the Slides with nice effects (it's a fancier Rad Rotator).   That works wonderful.

However, on the back-end in the create/edit screens, we need to re-order the slides when we want to feature a new slide in the #1 spot.  I would like to do one of two things:

 1. Override the default Create method so I can call that base functionality PLUS update all other Slides On Create, or

 2. Add an event trigger that will serve as a callback command after a create, update, or delete event for a Slide.

Peace,
Brian

Posted by Community Admin on 24-Apr-2014 00:00

Hello Brian,

I suggest you subscribe for the IDataEvent, which is fired for Create, Update, Delete of content items. You should add the following code snippet to your Global.asax file:

protected void Application_Start(object sender, EventArgs e)
       
           Telerik.Sitefinity.Abstractions.Bootstrapper.Initialized += new EventHandler<Telerik.Sitefinity.Data.ExecutedEventArgs>(Bootstrapper_Initialized);
 
       
 
       void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
       
           if (e.CommandName == "Bootstrapped")
           
               EventHub.Subscribe<IDataEvent>(Content_Action);
           
       
 
       private void Content_Action(IDataEvent @event)
       
           var action = @event.Action;
           var contentType = @event.ItemType;
           var itemId = @event.ItemId;
           var providerName = @event.ProviderName;
           var manager = ManagerBase.GetMappedManager(contentType, providerName);
           var item = manager.GetItemOrDefault(contentType, itemId);
       

You can add the file, if you do not have it in your solution from New Items -> Global Application File. The event will be fired when you update or create your dynamic item. The manager will get the item and you will be able to plug your code.
I hope this helps.

Regards,
Nikola Zagorchev
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed