Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Darren Hunter 105 posts 196 karma points
    Sep 15, 2023 @ 15:16
    Darren Hunter
    0

    Extending ContentPublishingNotification

    Hi,

    Is there a way to add a custome notification type to ContentPublishingNotification

    I am working on the following code:

    public class ContentHandler : INotificationHandler

        public ContentHandler(){}
    
        public void Handle(ContentPublishingNotification notification)
        {
            //Here we need to get the meta tags from the page content
    
           Boolean errorFound = false;
           var page = notification.PublishedEntities;
            foreach (var entity in page)
            {
               foreach(var p in entity.GetDirtyProperties())
                {
                    string metaName = p.ToString().ToUpper();
    
                    if (metaName == "METANAME" || metaName == "METADESCRIPTION" || metaName == "METAKEYWORDS")
                    {
                        string proprtyName = p;
                        var propertyValue = entity.GetValue(proprtyName);
    
                        if (propertyValue == null)
                        {
                            errorFound = true;
                        }                       
                    }
                }
    
                if (errorFound)
                {
    
                    notification.CancelOperation(new EventMessage("Content published, Please check SEO fields",
                           "One or more meta tags are missing.",
                           EventMessageType.Warning));
                }
    
            }
        }
    }}
    

    Insted of using notification.CancelOperation I like to add my own notification type so that I can get the oroginal Page Piblished message and then run my meta tag message

    But there dose not seem to be any documentation on how to do this in umbraco 10.

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Sep 16, 2023 @ 10:33
    Dennis Adolfi
    0

    Maybe you could append your own message as an additional message instead of canceling the operation?

    var customMessage = new EventMessage("CustomMetaTagsValidation", "Oops! It looks like one or more meta tags are missing.", EventMessageType.Warning);

    notification.Messages.Add(customMessage);

  • Darren Hunter 105 posts 196 karma points
    Sep 18, 2023 @ 07:32
    Darren Hunter
    1

    Thank you that work as I wanted.

Please Sign in or register to post replies

Write your reply to:

Draft