ContentService Notifications Example
Find out more about ContentService Notifications and explore some example of how to use it
Usage
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Notifications;
namespace Umbraco.Docs.Samples.Web.Notifications;
public class DontShout : INotificationHandler<ContentPublishingNotification>
{
public void Handle(ContentPublishingNotification notification)
{
foreach (var node in notification.PublishedEntities)
{
if (node.ContentType.Alias.Equals("announcement"))
{
var newsArticleTitle = node.GetValue<string>("title");
if (!string.IsNullOrWhiteSpace(newsArticleTitle) && newsArticleTitle.Equals(newsArticleTitle.ToUpper()))
{
notification.CancelOperation(new EventMessage("Corporate style guideline infringement",
"Don't put the announcement title in upper case, no need to shout!",
EventMessageType.Error));
}
}
}
}
}Variants and Notifications
Saving
Saved
Unpublishing
Unpublished
Publishing
Published
IContent Helpers
Last updated
Was this helpful?