Prevent Deleting / Unpublish and display notification to editor
Hello
I'm currently trying to prevent deletion and unpublishing of certain pages and media. I've got the following code:
private void ContentService_UnPublishing(IPublishingStrategy sender, PublishEventArgs<IContent> e)
{
foreach (var item in e.PublishedEntities)
{
if (this.IDsNotToBeDeleted.Contains(item.Id.ToString()))
{
e.Cancel = true;
e.Messages.Add(CreateWarningMessage(item.ContentType.Name));
break;
}
}
}
private void ContentService_Trashing(IContentService sender, MoveEventArgs<IContent> e)
{
foreach (var moveInfoItem in e.MoveInfoCollection)
{
if (this.IDsNotToBeDeleted.Contains(moveInfoItem.Entity.Id.ToString()))
{
e.Cancel = true;
e.Messages.Add(CreateWarningMessage(moveInfoItem.Entity.Name));
break;
}
}
}
private static EventMessage CreateWarningMessage(string name)
{
var eventMessage = new EventMessage("Warning", string.Format("Can not delete {0}", name), EventMessageType.Error);
return eventMessage;
}
The message appears for the Trashing event (content), but doesn't work for Unpublishing event (content), the Unpublish button just hangs with the spinner spinning, and in the console I get the following error:
Prevent Deleting / Unpublish and display notification to editor
Hello
I'm currently trying to prevent deletion and unpublishing of certain pages and media. I've got the following code:
The message appears for the Trashing event (content), but doesn't work for Unpublishing event (content), the Unpublish button just hangs with the spinner spinning, and in the console I get the following error:
With Media Trashing event, I get a similar problem - no message is displayed and an error appears in the console:
Any information on how to get these working would be great :-)
Cheers!
is working on a reply...