Reputation: 37
I am writing a module to have some functionality added to navigation menu whenever a content item, to which my module is attached, is published or unpublished. In my handler, that inherits from ContentHandler class, i have overwritten 'published' and 'unpublished' methods and the functionality is working as expected. However, the issue is, the content handler methods in my module, are invoked even for content types that do not have my module (content part) attached to them.
I also tried inheriting from 'IContentHandler' instead of 'ContentHandler' but same result.
Is there any way to bind the 'published, publishing, unpublished etc' methods of ContentHandler, so that they are invoked only when a content item, to which the content part is attached, is modified?
Upvotes: 0
Views: 165
Reputation: 37
Alright, found an answer to this. Posting it here for informational purposes.
Once you create a content part say 'abcPart', to trigger the 'publishing, unpublishing' and other methods associated with ContentHandler, all you need to do is in the constructor of your part's handler, add this code.
public class MyHandler : ContentHandler
{
public MyHandler ()
{
OnPublishing<abcPart>((context, part) => {
/*your logic here*/
});
}
}
In this manner, code present inside the constructor's 'OnPublishing' section would only get triggered, whenever a content item, to which 'abcPart' is attached, is being published.
Upvotes: 3