I have written a class that extends ApplicationEventHandler in order to catch the publish event of certain document types.
I am struggling to find the documentation for V7.
I originally used Document.AfterPublish but noticed this is obsolete.
As such I used Umbraco.Core.Services.ContentService.Published += Content_Published;
I'm I correct to use this?
Also I placed the class in the App_Code folder, any other suggestions on where to place the class? (in terms of standards)
You are indeed correct to use the Published event on the Content Service class. You can place the class where ever fits within your website. Generally, I develop an additional class library to contain things such as Event Handlers but App_Code will work fine in your instance.
I saw your comments on a post from June about determining if the entity is new.
I could not see the IsNewEntity() as part of the ContentService.Published so I used node.HasIdentity; is this acceptable/best way to see if the entity is new?
Also does the ContentService.Saved fire as when someon saves and publishes?
I think the best way to do this is to use node.HasIdentity(). Another way is to use the IRememberBeingDirty interface, in ContentService.Saved event i.e:
foreach (var node in e.SavedEntities)
{
// Check if node is still created
var dirty = (IRememberBeingDirty)node;
var isNew = dirty.WasPropertyDirty("Id");
if (isNew)
{ // do anything } }
Application Event
I have written a class that extends ApplicationEventHandler in order to catch the publish event of certain document types.
I am struggling to find the documentation for V7. I originally used Document.AfterPublish but noticed this is obsolete. As such I used Umbraco.Core.Services.ContentService.Published += Content_Published; I'm I correct to use this?
Also I placed the class in the App_Code folder, any other suggestions on where to place the class? (in terms of standards)
Thank you as always!
Hi L,
You are indeed correct to use the Published event on the Content Service class. You can place the class where ever fits within your website. Generally, I develop an additional class library to contain things such as Event Handlers but App_Code will work fine in your instance.
Thanks, Dan.
Hi Dan,
Many thanks for your answer. Perfect!
Regards, L
Sorry Dan,
Any resources for V7 you know about with examples?
Regards, L
Hi L,
Here is an example I've used in the past. Although it uses the Saved event, the Published event should be similar.
Thanks, Dan.
Hi L,
you can find another example for using events in Umbraco 7 into my uNewsManager package:
http://our.umbraco.org/projects/website-utilities/unewsmanager
It includes a .cs-File with a good example to startup with eventhandling in umbraco.
Sören
Perfect Soren,
Just had a look, perfect examples of what I was looking for.
Regards, L
Hi Dan, Soren,
I saw your comments on a post from June about determining if the entity is new. I could not see the IsNewEntity() as part of the ContentService.Published so I used node.HasIdentity; is this acceptable/best way to see if the entity is new?
Also does the ContentService.Saved fire as when someon saves and publishes?
Sorry no more questions I promise :-)
Hi L,
I think the best way to do this is to use node.HasIdentity(). Another way is to use the IRememberBeingDirty interface, in ContentService.Saved event i.e:
Hope this help you.
Sören
Thank you Soren, I have used methodology.
L
is working on a reply...