Hello there,
I am fairly new to PW and PHP (spoiler alert: totally new to hooks). I am trying to add a few custom functions to the Admin for certain "patterns" that will be repeating throughout the site I am building. One example of such a pattern is this: I have a 'product' template with a Page Reference field for single page input, 'design'. Once selected, I need to set the title of the product page to the title of this design. I have added the below to the ready.php (pieced together based on whatever I have read up here, feel free to laugh 🙂). It does the job, but only in 2 saves, as upon the first one it throws a 'Missing required value'-error for the title, although the values do get visibly filled in. Can someone help me out with where I am going wrong here or how else to approach solving this?
$this->pages->addHookBefore('saveReady', null, 'buildTitle');
function buildTitle($event) {
$page = $event->arguments(0);
if($page->template != 'product') return;
if($page->template = 'product') {
$p = $page->design;
$page->title = $p->title;
}
}
Thanks much.