Possible to add storage filter or 'events' to contenttype instead of contentpart?

Topics: Core, General
May 20, 2014 at 3:56 PM
I'm trying to intercept the onCreated/onUpdated events when I create/update a contentitem of a type which I created in the CMS admin interface.

As a little hack I attached a storage filter to the TitlePart in which I do a switch on the ContentType but the following message floods my logs:
Having more than one storage filter for a given part is invalid.
Is it possible to properly attach a filter to a contentitem instead of a part?
May 20, 2014 at 6:30 PM

I would create A custom part, then add that part to the content type you want to monitor.

Next use the onupdated etc methods of the Handler.

What is the end goal?

May 20, 2014 at 10:06 PM
The data is stored elsewhere and I want to manage it in Orchard and intercept changes so I can immediately synchronize the data.

So I created a custom part and wrote a migration to attach it to the contenttype. I changed the handler to the correct part and I saw that the eventhandlers were being placed. However the events Creating/Created/Updating/Updated aren't firing anymore... Do parts need to have fields or can they be used as I'm doing which is more like an empty interface used for 'tagging' classes.

My migration is as follows:
            typeof(CountryPart).Name, cfg => cfg
                .WithDescription("Country Part")

                                                     cfg => cfg.WithPart(typeof(CountryPart).Name));
This is my part:
public class CountryPart : ContentPart


And the handler defining the event handlers
public class GenericContentHandler : ContentHandler
    public GenericContentHandler(IServicesManager serviceManager)
        OnCreating<CountryPart>((context, tags) => serviceManager.CreatingCountry(context.ContentItem));
        OnUpdated<CountryPart>((context, tags) => serviceManager.UpdatedCountry(context.ContentItem));
May 20, 2014 at 10:45 PM

You might be missing a Driver. If you don't have one for that part, then it wont work.

Marked as answer by RobertWebcare on 5/23/2014 at 3:58 PM
May 21, 2014 at 11:39 AM
That makes sense. But my driver doesn't need any implementation am I right?
May 21, 2014 at 5:27 PM

The driver can be empty, that's fine

May 21, 2014 at 7:46 PM
I thought that the part itself was the 'glue' between the contentitem and code but that seems to be the driver. Thanks!