Forum
Use case for 'page.create' event
Hi,
I was wondering what the appropriate use for the page.create
event is? It doesn't appear to fire when creating a new page using the 'Add Page' or 'Add New Subpage' controls. I can only find one reference to it in Core and the comment suggests it only fires when using the upgrade app?
/**
* Find a page based on its path, or create a new one. Used by the Upgrade app.
* @param string $path A root-relative site path
* @return object Instance of Page class.
*/
on line 18-23 of PerchContent_Pages.class.php.
I'm trying to figure out a way of modifying page attributes on page creating using events, is this the right event to be listening out for or is there a more suitable one for the task?
Thanks.
I don't think we use it at all, and I'm not sure there's a use case. I think it's more a case that it's been added when that code was last touched as part of rolling improvements.
Would it be possible in a future update to re-add it to execute when using the 'add new page / subpage' buttons?
Alternatively, is there an easier way of setting a default page attributes template per master-page that wouldn't require event hooks? I've checked the docs and master page options and seen no option to do so.
What's the end objective?
I'm currently building a more complicated navigation section using page attributes in a specific template that has additional fields on top of the SEO ones, which is a list of careers / activities that can be filtered using categories. Using a list-detail approach didn't seem as suitable as the client would want greater control over the page meta-data in this instance.
At the moment when they create a new page, they are taken to the page options section and have to select the correct set of page attributes to make this work. The original question was to see if I could listen out for a page create event and set this without the client having to choose in a quick and dirty way. If Perch could do this without the need for custom code, similar to 'copy regions from' or somehow read the value set using the
perch_page_attributes
function like existing region that would save some support calls when the client forgets to set the correct attribute file.Bit of a waffle there, in basic terms it would be nice to be able to attach attribute templates to pages in the Perch UI to save some steps for clients when using multiple attribute templates.
Hmm, ok, I'll give it some thought.