Copied to clipboard

Flag this post as spam?

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


  • NSC 12 posts 102 karma points
    Oct 05, 2021 @ 11:42
    NSC
    0

    Notification return types and extracting values

    With some notifications like ContentMovedToRecycleBinNotification and ContentDeletedNotification the return type is IContent, not IPublishedContent like the notifications from ContentUnpublishedNotification and ContentPublishedNotification.

    When extracting the values from IPublishedContent it's fairly straight forward, but when trying to do the same for IContent I often end up with paths to related documents like umb://document/b7b20e1fe0b14f79866e42dc24b9cc8f, instead of the document itself or in another example where I have a toggle/boolean, which in the IContent object simply has information about the property, but not the actual value of the property.

    How do I get to my values in IContent? Or do I have to do something different to work around it and avoid IContent altogether?

  • Thomas Kassos 54 posts 259 karma points
    Oct 05, 2021 @ 12:31
    Thomas Kassos
    0

    Hi,

    have you tried something like this?

    notification.MoveInfoCollection.FirstOrDefault().Entity.GetValue<bool>("{yourProperty}");
    

    or maybe try to inject the Umbraco helper and use the Enity.Id to get the IPublished content.

    This one may not work for ContentDeletedNotification as the item will not exist anymore

    public class Testing : INotificationHandler<ContentMovedToRecycleBinNotification>
    {
        private readonly UmbracoHelper _umbracoHelper;
    
        public Testing (IHttpContextAccessor contextAccessor)
        {
            if (contextAccessor.HttpContext == null) throw new NullReferenceException("Can not get umbraco context");
    
            _umbracoHelper = contextAccessor.HttpContext.RequestServices.GetRequiredService<UmbracoHelper>();
        }
    

    }

Please Sign in or register to post replies

Write your reply to:

Draft