Getting PageNode from PageDraft

Posted by Community Admin on 04-Aug-2018 04:09

Getting PageNode from PageDraft

All Replies

Posted by Community Admin on 04-Jan-2016 00:00

Hi there,

I want to create a dynamic module item for pages automatically when they're created.

The dynamic module has a page "related item" which I want to set to the new page that's being created.

I've hooked into the PageManger.Executing event as described here:

www.sitefinity.com/.../what-event-is-raised-when-a-page-is-published-and-how-do-i-capture-it

... however, I am having trouble getting the linked page item with this code snippet from the dynamic module ...

                                            PageManager linkedPageManager = PageManager.GetManager();
                                            
                                            var linkedPageItem = linkedPageManager.GetPageNodes().FirstOrDefault(p => p.Id == page.Id);
                                            if (linkedPageItem != null)
                                           
                                                // This is how we relate an item
                                                articleItem.CreateRelation(linkedPageItem, "LinkedPage");
                                           

... linkedPageItem is always null, I presume because the "page" object is a PageDraft and not a PageNode.

Is what I'm trying to do achievable? Is there a way to get the Id of the new page at this point in time? (in the PageManager_Executing event)

Thanks,
Michael

Posted by Community Admin on 04-Jan-2016 00:00

Hello Michael,

You can try using the executed event instead:

PageManager.Executed

You can also use the IDataEvent and filter by item type and status:
http://docs.sitefinity.com/for-developers-idataevent

Regards,
Nikola Zagorchev
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 06-Jan-2016 00:00

Thanks for the reply Nikola.  I'll check out your suggestions, but I ended up getting it working using ParentPage.NavigationNodeId like this:

 

PageManager linkedPageManager = PageManager.GetManager();

                                            PageNode linkedPageItem = linkedPageManager.GetPageNodes().FirstOrDefault(p => p.Id == page.ParentPage.NavigationNodeId);

 

... can you see any problems with this approach? It seems to be working fine for what I need, but am not sure if there are scenario's where this will fail (?)

 

Cheers,
Michael

Posted by Community Admin on 07-Jan-2016 00:00

Hello Michael,

Your query can result in Null reference exception if the page node does not have a parent - in a case where ParentPage returns null.
The ParentPage property will return a PageData object and its NavigationNode is Id of the PageNode the data is linked to.
You can also refer to the following articles:
http://docs.sitefinity.com/for-developers-query-pagedata-by-pagenode-id

http://docs.sitefinity.com/for-developers-query-pagedata-by-url-of-the-pagenode

Regards,
Nikola Zagorchev
Telerik

 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 07-Jan-2016 00:00

Thanks very much for your help Nikola

Posted by Community Admin on 08-Jan-2016 00:00

Hello Michael,

I am glad you have managed to achieve the desired result.

Regards,
Nikola Zagorchev
Telerik

 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 24-Oct-2017 00:00

Hi, I'm also trying to register an event and use the publish event to trigger some custom code. I've used this article to register my event: www.sitefinity.com/.../what-event-is-raised-when-a-page-is-published-and-how-do-i-capture-it

However, I'm not sure how I can get the page URL of the page thats being published. Can someone provide sample code on how to retrieve the page URL of the page thats being published when the publish event is triggered?

Thanks,

Allen

This thread is closed