Subscribe to Create and/or Update events dynamic modules
Hi,
I'd like to know if it is possible to subscribe to the Create and Update events of a dynamic module item.
I'd like to store a shortened url within a dynamic content and to me it seems that the best place to generate such url, is during the creation or update of an item.
If someone knows how this could be done, or knows a better way, please share it?
Thanks!
Daniel
Hi,
Yes this is possible by subscribing to the lifecycle events of the content modules. The approach is to create a custom decorator as described in this KB article. The approach is to have a separate decorator for each module you want to handle lifecycle events like publish, modify (delete is a separate topic). The decorator attaches to an event, for example publish.
When we talk about a custom decorator that will handle dynamic content (module builder) you have to change the registration of the decorator in Global.asax. This is necessary because in Dynamic modules the items you create are not inheriting from content and while all other modules (news, blogs, events), register a decorator that will handle content
new
InjectionParameter<Action<Content, Content>>(
null
),
Dynamic modules register the decorator like this:
protected
void
Application_Start(
object
sender, EventArgs e)
Bootstrapper.Initialized +=
new
EventHandler<Telerik.Sitefinity.Data.ExecutedEventArgs>(Bootstrapper_Initialized);
void
Bootstrapper_Initialized(
object
sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
if
(e.CommandName ==
"Bootstrapped"
)
ObjectFactory.Container.RegisterType<ILifecycleDecorator, CustomDecorator.NewsDecorator>
(
typeof
(DynamicModuleManager).FullName,
new
InjectionConstructor(
new
InjectionParameter<ILifecycleManager>(
null
),
new
InjectionParameter<LifecycleItemCopyDelegate>(
null
),
new
InjectionParameter<Type[]>(
null
)
)
);
DynamicContent newsItem = masterItem
as
DynamicContent;
// add logic that will be executed when item is publsihed
return
base
.ExecuteOnPublish(masterItem, liveItem, culture, publicationDate);
DynamicContent dynamicContent = item
as
DynamicContent;
string
dynamicContentType = dynamicContent.GetType().FullName;
if
(dynamicContentType.Equals(TesetingModules.TestModule.FullName))
// execute logic for one module called TestingModule
.. add another module logic below
Hi Stanislav,
I will figure it out with this information.
Thanks for the explanation and help!
Regards,
Daniel
From Slavo: www.sitefinity.com/.../dynamic-modules-events
Hi there,
I've followed these posts in the past and had them working as expected in v5.2; however I seem to have encountered an issue with 5.4. (which I don't believe was there in the previous version) I have a dynamic module created, and I go to update the content (update the description text). All of the events are fired now (whereas I swear in the past they weren't). the ContentCreatedEventHandler, ContentDeletedEventHandler and ContentUpdatedEventHandler (multiple times to boot!). This doesn't seem right to me (if I update content, then I expect only the ContentUpdatedEventHandler to fire -- not the others). ... any ideas? Has anybody else encountered this?
How I have it wired up in global.asax:
if (e.CommandName == "Bootstrapped")
EventHub.Subscribe<IDynamicContentCreatedEvent>(evt => this.ContentCreatedEventHandler(evt));
EventHub.Subscribe<IDynamicContentDeletedEvent>(evt => this.ContentDeletedEventHandler(evt));
EventHub.Subscribe<IDynamicContentUpdatedEvent>(evt => this.ContentUpdatedEventHandler(evt));
EventHub.Subscribe<IMediaContentDownloadedEvent>(evt => this.MediaContentDownloadedEven(evt));
It seems as though for dynamic content items, when you update an existing item, sitefinity actually deletes that item, and then re-creates it?? is that right?
Thanks,
Hi,
Try with this snippet to attach to an event.
if
(e.CommandName ==
"Bootstrapped"
)
EventHub.Subscribe<IDynamicContentCreatedEvent>(
new
SitefinityEventHandler<IDynamicContentCreatedEvent>(OnLogin));
//...
void
OnLogin(IDynamicContentCreatedEventloginEvent)