torf Posted March 10, 2022 Share Posted March 10, 2022 Hi everybody, I tried to make only special pages accessible through a page reference field, but got a strange problem. In my ready.php I added $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->hasField == "choose_page") { $event->return = $event->pages->find("template=template_name_to_choose_from"); } }); But I keep getting all pages of my site back when I use autocomplete for my field. With select or radio it works as expected. Can anybody tell me why? Link to comment Share on other sites More sharing options...
Zeka Posted March 12, 2022 Share Posted March 12, 2022 Hi @torf Have you tried to hook InputfieldPageAutocomple::findPagesSelector? Link to comment Share on other sites More sharing options...
torf Posted March 13, 2022 Author Share Posted March 13, 2022 Oh. I didn't know this one. I just tried $wire->addHookAfter('InputfieldPageAutocomple::findPagesSelector', function($event) { if($event->object->hasField == "choose_page") { $event->return = $event->pages->find("template=template_name_to_choose_from"); } }); but to no avail. I still get every page returned. Or maybe I have misunderstood how to use it. What puzzles me is that it works perfectly with Dropdwon or Select. How is Autocomplete different? Link to comment Share on other sites More sharing options...
Robin S Posted March 13, 2022 Share Posted March 13, 2022 On 3/11/2022 at 4:41 AM, torf said: But I keep getting all pages of my site back when I use autocomplete for my field. With select or radio it works as expected. The "Multiple page selection" version of Page Auto Complete doesn't support the "Custom PHP code" option (i.e. the InputfieldPage::getSelectablePages hook). In earlier versions of PW it used to be more explicit about that. Now it just removes the "Custom PHP code" option depending on what you have selected in "Input field type". Page List Select and Page List Select Multiple also do not support the "Custom PHP code" option. On 3/11/2022 at 4:41 AM, torf said: $event->return = $event->pages->find("template=template_name_to_choose_from"); If you really are returning something like that from you hook then you could change to the "Selector string" option, which will work with autocomplete. 2 Link to comment Share on other sites More sharing options...
torf Posted March 14, 2022 Author Share Posted March 14, 2022 I see. Thanks for the clarification @Robin S I use a German backend translation and it seems the filter for showing only valid options does not show up in German... Sadly the selector is a bit more complicated in reality. Pages are chosen based on a value in another page selector field they hold. So the original selection is $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->hasField == "choose_page") { $page = $event->arguments(0); $zv = $page->parent->title; $event->return = $event->pages->find("template=my_Template, field_in_my_Template=$zv"); } }); I do not think that can be achieved without php. Link to comment Share on other sites More sharing options...
Robin S Posted March 14, 2022 Share Posted March 14, 2022 2 hours ago, torf said: I do not think that can be achieved without php. It might work as a selector string: template=my_Template, field_in_my_Template=page.parent.title Or if field_in_my_Template is a Page Reference field: template=my_Template, field_in_my_Template=page.parent 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