fredbob Posted February 5, 2017 Share Posted February 5, 2017 Hi, I have a field on a page that I am trying to set the selectable pages to the parent pages, multi page field. -- Parent (has page field with pages I want to select from) -- -- Child (has field that needs to be able to select pages from the parents page field) I have tried using custom PHP selectors, but in the new version of processwire the custom PHP selector has been changed into a hook. I am not sure how to write it, any help would be appreciated. Quote Add the following hook to a /site/ready.php file and modify per your needs. The hook should find and return selectable pages in a PageArray. $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->name == 'result_judge_challenge') { $event->return = $event->pages->find('your selector here'); } }); If you need to know the page being edited, it is accessible from: $event->arguments('page'); Cheers. Link to comment Share on other sites More sharing options...
kongondo Posted February 5, 2017 Share Posted February 5, 2017 (edited) I have no idea why you have such a setup but anyway, here goes. As per the instructions, your Hook needs to return a PageArray. This is untested: $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->name == 'result_judge_challenge') { $page = $event->arguments('page'); $event->return = $page->parent->parent_multi_page_field;// this should return a PageArray } }); You might want to add checks to see if the parent page actually has items in its page field. Edited February 5, 2017 by kongondo 4 Link to comment Share on other sites More sharing options...
fredbob Posted February 5, 2017 Author Share Posted February 5, 2017 That worked perfectly thank you! I was trying to do it without putting it into a variable first like this $event->return = $page->parent->parent_multi_page_field; Link to comment Share on other sites More sharing options...
Martin Muzatko Posted April 15, 2017 Share Posted April 15, 2017 Hello! I'm trying to have a custom page selector as well, but when I select a pageArray for a select field, I get the following error: Link to comment Share on other sites More sharing options...
Martin Muzatko Posted April 15, 2017 Share Posted April 15, 2017 I found out: Even if the select is a MultiPage Select, I still get the error. Link to comment Share on other sites More sharing options...
LostKobrakai Posted April 18, 2017 Share Posted April 18, 2017 @Martin Muzatko Could you please share the code you're using. Link to comment Share on other sites More sharing options...
Martin Muzatko Posted April 18, 2017 Share Posted April 18, 2017 Hello @LostKobrakai. As documented for custom selectors for PW 3+: <?php $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->name == 'ticket') { $page = $event->arguments('page'); $result = $page->parent()->parent()->children('template=event-tickets')->children(); print_r($result); $event->return = $result; } }); This selection happens from within a Registration. See example structure here: Thank you already! Link to comment Share on other sites More sharing options...
LostKobrakai Posted April 18, 2017 Share Posted April 18, 2017 // Page > Page > Page > PageArray > children() // There's no PageArray::children() method $result = $page->parent()->parent()->children('template=event-tickets')->children(); // Use this: $result = $page->parent()->parent()->child('template=event-tickets')->children(); // Or even $event = $page->closest('template=event'); $tickets = $pages->find('has_parent=$event, parent.template=event-tickets'); 3 Link to comment Share on other sites More sharing options...
Martin Muzatko Posted April 18, 2017 Share Posted April 18, 2017 Ugh! This makes sense and it works perfectly. The debug message looked like there was a problem with the result being a PageArray, not that PageArray has no children method. Thank you a lot @LostKobrakai! Link to comment Share on other sites More sharing options...
LostKobrakai Posted April 18, 2017 Share Posted April 18, 2017 To be honest I've no idea where the error message did come from. It's certainly highlighting a some different thing. 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