November Happy Hour will be moved to Thursday December 5th.

Page Type Node Becomes None Editable when intercepting PublishedContent Event

Ayo
Ayo
Vote:
 

I am hooking in to the PublishedContent Event within Episerver, so when a user publishes a particular page type some logic is performed (create pdf) and a string value is saved in to one of the properties.(the path to the pdf)

This is working, the PDF is created and the path to the PDF is also saved.

However the problem I have is after the publish is complete, all the properties become readonly, I have to click another node, then click that one again before I can edit it. - Is this normal, or is it something to do with the way I do the save?

This is my code:

public void Initialize(InitializationEngine context)
        {
            var events = ServiceLocator.Current.GetInstance();
            events.PublishedContent += EventsPublishedContent;
        }

        private void EventsPublishedContent(object sender, ContentEventArgs e)
        {
            if (e.Content is myType)
            {
                var currentPage = e.Content as RatePlanPageType;

                var pdfPath = businessLogic.CreatePdf(e.content);

                var clone = currentPage.CreateWritableClone();

                clone.Property["PdfFiles"].Value = pdfPath;

                var contentRepository = ServiceLocator.Current.GetInstance();

                contentRepository.Save(clone, SaveAction.Save);
            }

This is a screen shot after saving

If I click another node in the tree, then click this one again, it goes back to normal and all the data is saved correctly.

#190730
Apr 16, 2018 15:41
Vote:
 

Your code publishes a new version of the content (check the versions gadget to confirm this). This means that you are no longer looking at the primary draft therefore the UI makes it readonly. You can hook into the publishing event which should stop this behaviour or don't publish a new version of content in your Save method.

#190732
Edited, Apr 16, 2018 16:01
Ayo
Vote:
 

Thank you David, I didn't relise that I was hooked in to the wrong method, changed it from 

events.PublishedContent
to
events.PublishingContent

and it works perfectly.

#190737
Apr 16, 2018 16:12
Vote:
 

which just shows again that events are named wrong or confusing at least ;)

events.BeforePublishContent()

events.AfterPublishContent()

would be less confusing for me.

#190789
Apr 16, 2018 22:09
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.