Copied to clipboard

Flag this post as spam?

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


  • Jon 92 posts 166 karma points
    Mar 17, 2021 @ 15:46
    Jon
    0

    Capture event when publishing Page with all its child pages

    In Umbraco when I publish a single page I can hook into the Event by using something like this:

            ContentService.Publishing += this.ContentService_Publishing;
            ContentService.Published += this.ContentService_Published;
            ContentService.SentToPublish += this.ContentService_SentPublish;
    

    BUT - what I would like to do is to hook into the event when I publish a page with all its child pages. Is there a way to do this in Umbraco 8?

    Thanks

    Jon

  • Malthe Petersen 68 posts 383 karma points c-trib
    Mar 17, 2021 @ 19:41
    Malthe Petersen
    1

    Hi Jon.

    It works the way that when you click the “publish with descendants” button Umbraco triggers a publish for each of the descendants that have been unpublished, but is now being published.

    If you want to make sure to capture every time Umbraco does something with descendants, you should hook into the cache refreshed event and check if the “ChangeType” is equal to “TreeChangeType.RefreshBranch”.

    This change type is used when a parent is being:

    • published from unpublished state
    • unpublished

    And I am pretty sure that it also triggers when you click the publish with descendants button.

    You can take a look at what I have done here: https://github.com/enterspeedhq/enterspeed-source-umbraco-cms/blob/8b4cb323e35b2159fdea100754862e4dd528cb3f/src/Enterspeed.Source.UmbracoCms.V8/Components/EnterspeedContentEventsComponent.cs#L238

    In short: when Umbraco does something to the “branch”, aka to everything below the current node, we fetch the descendants and handles them as well.

    Hope this helps.

    Regards

  • Jon 92 posts 166 karma points
    Mar 18, 2021 @ 10:14
    Jon
    0

    Thank you so much - this is exactly what I was looking for :)

  • Malthe Petersen 68 posts 383 karma points c-trib
    Mar 18, 2021 @ 10:50
    Malthe Petersen
    0

    Perfect! Happy to help. :-)

Please Sign in or register to post replies

Write your reply to:

Draft