Copied to clipboard

Flag this post as spam?

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


  • Sam Horne 11 posts 61 karma points
    Jun 26, 2013 @ 04:32
    Sam Horne
    0

    PublishingStrategy.Publishing Event in v6

    I am attempting to capture (using v6's new PublishingStrategy events) the publishing event of a content node and save some additional properties to it., as well as add protection. However, for newly publishing content nodes - the ID is always 0. As this event is fired from ContentService.SaveAndPublish() method, I can't see any way to access the node's ID during this event.

    My code:-

    INSIDE MY APPLICATION EVENTS REGISTER:
    PublishingStrategy.Publishing += PublishingTrainingMaterials;

    THE EVENT METHOD:
    private void PublishingTrainingMaterials(IPublishingStrategy sender, PublishEventArgs<IContent> e)
            {
           foreach (var item in e.PublishedEntities)
                {
                    if (item.ContentType.Alias == DocumentTypeAlias.EkitTrainingMaterial)
                    {
                        var content = (Content)item;
                        // get login and unauthorised node ids
                        int loginNodeId = 1234;
                        int unauthorisedNodeId = 1235;

                        Access.ProtectPage(false, item.Id, loginNodeId, unauthorisedNodeId);

                        // set 'hide in navigation' properties to page
                        content.SetValue(DocumentPropertyAlias.HideInNavigation, true);
                    }
                }
          }

    Previously in v4, the event 'Document.BeforeSave' could access the node's ID.

    Does anyone have any suggestions or corrections, or explanations why I cannot intercept the node before its published (but after it's saved and designated a node ID) ?

    Is there ANY documentation on these new PublishingStrategy events - namely what is and what is not accessible from both the 'Publishing' and 'Published' events. Google and Our.Umbraco searches bring up nada on this new functionality in v6.

    Thanks in advance.

  • Sam Horne 11 posts 61 karma points
    Jun 26, 2013 @ 04:54
    Sam Horne
    100

    Update:

    I've found (through sheer trial and error) that using the [ContentService.Saved ] event is the v6 equivalent of doing Document.AfterSave in v4. Which is the point where the content has been created, and then saved (i.e. designated an ID).

    APPLICATION EVENT
    ContentService.Saved += PublishingTrainingMaterials;

    EVENT HANDLER
    private void PublishingTrainingMaterials(IContentService service,SaveEventArgs<IContent> e) { ... }

    Another note, while creating content programmatically via the API, its important to use ContentService.CreateContent() to create the content object, as opposed to make a new instance of Models.Content. I'm not sure if this has been documented anywhere (or if it needs to be). Any other pointers to doucmentation would be helpful.

    In advance, I understand this is an open source project - I'm not complaining, I would just like to know more (as I'm sure a lot of other developers would).

Please Sign in or register to post replies

Write your reply to:

Draft