This project is read-only.

Event for updating content type definition

Topics: Troubleshooting, Writing modules
May 20, 2013 at 11:01 AM
Edited May 20, 2013 at 12:00 PM
how can I "detect" the moment when user is creating new content type (not item)? I'd like to do sth like this:
if (ContentTypeDefinition.PartsDefinition.Contains("myPart")) {
I've tried to use ContentHandler, but none of event was called when saving new content type definition.

OK, to close. I handled it.
May 20, 2013 at 2:42 PM
I need another event: removing content type. Is there any event for that?
May 21, 2013 at 11:12 AM
There's no event for that, although it does signal to invalidate a cache. Perhaps you can somehow listen for that signal as the cache does. However, this signal is triggered for other actions as well, so it would still be tricky to determine what the triggered the signal.
May 21, 2013 at 10:40 PM
Ok, maybe there is a workaround: what about overriding route to redirect to my action that handles additional actions and then redirect to stock Orchard action controller. What about it? Where can I find controller for Admin/CotnentType/Edit route?
May 22, 2013 at 12:07 AM
Sure, that could work, although I'm not sure how you would handle the POST requests, but worst case you reimplement the AdminController yourself.
You'll find the controller in Orchard.ContentTypes.
May 22, 2013 at 10:38 AM
Edited May 22, 2013 at 10:39 AM
Since 1.7 you will be able to make use of the new NHibernate-related extension points for plugging into session pipeline. This way you could detect if a record with a given name gets created/updated. Check Orchard.Framework\Data\ISessionInterceptor.cs in the latest code in 1.x branch.
May 22, 2013 at 4:40 PM
Thanks, I will take a look and try both solutions.