Pixrael Posted September 28, 2017 Share Posted September 28, 2017 I have a Page Reference Field and I need to select only the children pages of the current page where the field is edited. But the problem here is that the field is inside a Repeater, and the repeaters are actually another pages in the tree.. so where I can do easily using a custom code in ready.php like this: $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->hasField == 'page_list') { $event->return = $event->arguments('page')->children; } }); this don't work If the field is inside a Repeater.. I need to get the related page to the current repeater page to get the children, but how to do it? Link to comment Share on other sites More sharing options...
abdus Posted September 28, 2017 Share Posted September 28, 2017 Try using ... ('page')->getForPage()->children instead Link to comment Share on other sites More sharing options...
Pixrael Posted September 28, 2017 Author Share Posted September 28, 2017 I try it but in the Field setting page I get this error: ProcessField: Method Page::getForPage does not exist or is not callable in this context and in the Page edit i get this: InputfieldRepeaterMatrix: Repeater 'layouts_main' preload 'page_list': Method Page::getForPage does not exist or is not callable in this context Link to comment Share on other sites More sharing options...
abdus Posted September 28, 2017 Share Posted September 28, 2017 (edited) This one seems to work for me. $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->hasField == 'page_list') { $event->return = $event->object->hasPage->children; } }); Edit: Nope. ->hasPage gives the repeater item page (not exactly, keep reading), ->arguments('page') gives the page being edited. $this->addHookAfter('InputfieldPage::getSelectablePages', function (HookEvent $e) { if ($e->object->hasField->name != 'testReference') return; $e->return = $e->arguments('page')->children; }); Weird thing is that InputfieldPage::getSelectablePages is called twice for every new repeater item. On the first call, hasPage and arguments('page') are identical, but on the second call, hasPage is the repeater item, arguments('page') is the page being edited. So using the argument seems to be the better option. Edited September 28, 2017 by abdus 1 Link to comment Share on other sites More sharing options...
Pixrael Posted September 28, 2017 Author Share Posted September 28, 2017 Ooooh my fault!! ..the original code (the first) works, the problem is that my child pages was unpublished and children() filter it.. you last code don't work.. but thanks a lot! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now