-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Short description of the issue
When using the "Custom PHP code" option to limit selectable pages for a Page Reference field, the example code given is:
$wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) {
if($event->object->name == 'my_page_field') {
$event->return = $event->pages->find('your selector here');
}
});
But the if()
condition will fail when the field is contained within a repeater item because in that case the inputfield name will be my_page_field_repeater1234
. Users may not know how to debug this issue and it would be better if the example code worked for all contexts where a Page Reference field may be used.
Related forum post: https://processwire.com/talk/topic/13677-selectable-pages-for-page-field-inside-a-repeater-inside-a-repeatermatrix/?do=findComment&comment=145194
Optional: Suggestion for a possible fix
While the inputfield name changes when used inside a repeater, the name of the field associated with the inputfield does not change. So perhaps the example code could be changed to:
$wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) {
if($event->object->hasField->name == 'my_page_field') {
$event->return = $event->pages->find('your selector here');
}
});