Handling an adding new item event in dynamic module
I've created new dynamic module with Module Builder (for example Products). I would like to do some actions when I add new item to content Products. Is it possible to handle that event?
I will be very grateful to someone who will help with suggestions.
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 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,
I created a decorator for a dynamic module using the code you ve provided and also the kb.
But I get this error in the global.asax file
CS0308: The non-generic method 'Telerik.Microsoft.Practices.Unity.IUnityContainer.RegisterType(System.Type, System.Type, string, Telerik.Microsoft.Practices.Unity.LifetimeManager, params Telerik.Microsoft.Practices.Unity.InjectionMember[])' cannot be used with type arguments
<%@ Application Language=
"C#"
%>
<script runat=
"server"
>
void
Application_Start(
object
sender, EventArgs e)
// Code that runs on application startup
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"
)
Telerik.Sitefinity.Abstractions.ObjectFactory.Container.RegisterType<Telerik.Sitefinity.Lifecycle.ILifecycleDecorator, CustomDecorator.DynamicModulesDecorator>
(
typeof
(Telerik.Sitefinity.DynamicModules.DynamicModuleManager).FullName,
new
Telerik.Microsoft.Practices.Unity.InjectionConstructor(
new
Telerik.Microsoft.Practices.Unity.InjectionParameter<Telerik.Sitefinity.Lifecycle.ILifecycleManager>(
null
),
new
Telerik.Microsoft.Practices.Unity.InjectionParameter<Telerik.Sitefinity.Lifecycle.LifecycleItemCopyDelegate>(
null
),
new
Telerik.Microsoft.Practices.Unity.InjectionParameter<Type[]>(
null
)
)
);
void
Application_End(
object
sender, EventArgs e)
// Code that runs on application shutdown
void
Application_Error(
object
sender, EventArgs e)
// Code that runs when an unhandled error occurs
void
Session_Start(
object
sender, EventArgs e)
// Code that runs when a new session is started
void
Session_End(
object
sender, EventArgs e)
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
</script>
<%@ Import Namespace="Telerik.Microsoft.Practices.Unity" %>
[quote]Nidhi said:
<%@ Import Namespace="Telerik.Microsoft.Practices.Unity" %>
[/quote]
Thank you! I knew there had to be some missing import with an extension method somewhere but couldn't find it until I found this post.