[TcmExtension("PageEventHandlerExtension")]
public class PageEventHandler : TcmExtension
{
public PageEventHandler()
{
Subscribe();
}
public void Subscribe()
{
EventSystem.Subscribe<Page, PublishOrUnPublishEventArgs>(PagePublishOrUnpublishAction, EventPhases.Initiated);
}
private static void PagePublishOrUnpublishAction(Page page, PublishOrUnPublishEventArgs args, EventPhases phase)
{
if (page.Metadata==null)
{
throw new PublisherException(new LocalizableMessage(Resources.Properties.DoNotPublish));
}
}
}
In above method in Tridion Event System I am trying to forcefully terminate the publishing of a page.
While debugging I was able to hit the statement which is throwing the exception, but even then the item gets published successfully. Am I doing it the wrong way, if yes how can I fail the publishing of an item?