Hi,
I have a page with a select
field within it, that looks like this:
settingType:
type: select
label: Setting type
default: primary
empty: false
width: 1/3
options:
primary: Primary
secondary: Secondary
university: University
alternative: Alternative provision
I need to set up a hook that checks when the page is saved, and if the contents of this field has changed, to move the page to a new location based on this. I have pages with slugs that match the values of the select
, but am struggling to get this to work. This is what I have in my hook:
'page.update:after' => function (Kirby\Cms\Page $newPage, Kirby\Cms\Page $oldPage) {
if($newPage->intendedTemplate() == 'setting'):
if($newPage->settingType() !== $oldPage->settingType()):
$newPage->move(???) // This needs to be the new parent page using the value of settingType e.g. 'university'
endif;
endif;
},
I can’t get the move to work as I would like. It needs to move the page to a parent with the slug the value of the select field, but I am not sure what to put inside the move here.
If anyone has any thoughts that would be super.