a-ok Posted September 20, 2017 Share Posted September 20, 2017 Hi folks, I want to return a few repeater items via a PageField and originally I would do this by writing the commented out code in the PHP area provided BUT now it states I should be doing this in ready.php via a hook. I have written the below... following from the example given in the backend but it's not returning anything in the PageField dropdown. The message I set up to do a bit of debugging seems to be returning the correct items. Any thoughts? And am I able to return the title of the repeater item being chosen as the getForPage()->title as shown below (how I previously did it). $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if ($event->object->name == 'home_whatson_article') { $event->return = $event->pages->find("template=repeater_events_detail_dates, events_detail_dates_start_date>today, sort=events_detail_dates_start_date"); $this->message($event->return); /* $options = new PageArray(); foreach ($pages->find("template=repeater_events_detail_dates, events_detail_dates_start_date>today, sort=events_detail_dates_start_date") as $e) { $e->title = $e->getForPage()->title; $options->add($e); } return $options; */ } }); Link to comment Share on other sites More sharing options...
abdus Posted September 20, 2017 Share Posted September 20, 2017 InputfieldPage::getSelectablePages doesnt work with all input types protected static $defaultInputfieldClasses = array( 'InputfieldSelect', // works 'InputfieldSelectMultiple', // works 'InputfieldCheckboxes', // works 'InputfieldRadios', // works 'InputfieldAsmSelect', // works 'InputfieldPageListSelect', // doesnt work 'InputfieldPageAutocomplete', // doesnt work ); Because it's called only if inputfield has addOption() method // InputfieldPage.module /** * Get delegate Inputfield for page selection * * @return Inputfield|null * @throws WireException * */ public function getInputfield() { // ... if(method_exists($inputfield, 'addOption')) { $children = $this->getSelectablePages($page); if($children) { foreach($children as $child) { $label = $this->getPageLabel($child); $inputfield->addOption($child->id, $label); } } } // ... } Link to comment Share on other sites More sharing options...
a-ok Posted September 20, 2017 Author Share Posted September 20, 2017 1 minute ago, abdus said: InputfieldPage::getSelectablePages doesnt work with all input types protected static $defaultInputfieldClasses = array( 'InputfieldSelect', // works 'InputfieldSelectMultiple', // works 'InputfieldCheckboxes', // works 'InputfieldRadios', // works 'InputfieldAsmSelect', // works 'InputfieldPageListSelect', // doesnt work 'InputfieldPageAutocomplete', // doesnt work ); Because it's called only if inputfield has addOption method() // InputfieldPage.module /** * Get delegate Inputfield for page selection * * @return Inputfield|null * @throws WireException * */ public function getInputfield() { // ... if(method_exists($inputfield, 'addOption')) { $children = $this->getSelectablePages($page); if($children) { foreach($children as $child) { $label = $this->getPageLabel($child); $inputfield->addOption($child->id, $label); } } } // ... } Thanks, abdus. My PageReference field is InputfieldAsmSelect Link to comment Share on other sites More sharing options...
abdus Posted September 20, 2017 Share Posted September 20, 2017 I tried using asmSelect, it works fine on my setup. Maybe you need include=all (repeater pages are hidden by default)? $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->hasField == 'tags') { $event->return = $event->pages->find('template=repeater_seo, include=all'); } }); Link to comment Share on other sites More sharing options...
a-ok Posted September 20, 2017 Author Share Posted September 20, 2017 4 minutes ago, abdus said: I tried using asmSelect, it works fine on my setup. Maybe you need include=all (repeater pages are hidden by default)? $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->hasField == 'tags') { $event->return = $event->pages->find('template=repeater_seo, include=all'); } }); I even changed it just to find all pages with a specific template (not a repeater) AND to a simple Select field (not ASM) and I get nothing. My PageReference field is in a repeater... could this be something that is killing it? Link to comment Share on other sites More sharing options...
a-ok Posted September 20, 2017 Author Share Posted September 20, 2017 Looks like it's to do with it being in a repeater Link to comment Share on other sites More sharing options...
abdus Posted September 20, 2017 Share Posted September 20, 2017 14 minutes ago, abdus said: Maybe you need include=all (repeater pages are hidden by default)? Link to comment Share on other sites More sharing options...
a-ok Posted September 20, 2017 Author Share Posted September 20, 2017 2 minutes ago, abdus said: Sorry it's the same field... for testing purposes I just tried to find events-detail templates. If you stick your example in a repeater it won't work. $event->return = $event->pages->find("template=events-detail"); Link to comment Share on other sites More sharing options...
a-ok Posted September 20, 2017 Author Share Posted September 20, 2017 It has to do with the PageField being inside a repeater... it works fine outside it. Link to comment Share on other sites More sharing options...
abdus Posted September 20, 2017 Share Posted September 20, 2017 It works fine inside repeaters too $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->hasField == 'pageRef') { $event->return = $event->pages->find('template=repeater_testRepeater, include=all'); } }); 1 Link to comment Share on other sites More sharing options...
a-ok Posted September 20, 2017 Author Share Posted September 20, 2017 2 minutes ago, abdus said: It works fine inside repeaters too $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->hasField == 'pageRef') { $event->return = $event->pages->find('template=repeater_testRepeater, include=all'); } }); Thanks for testing, abdus. It turns out my line if ($event->object->name == 'home_whatson_article') { needed to be your line if ($event->object->hasField == 'home_whatson_article') { 1 Link to comment Share on other sites More sharing options...
abdus Posted September 20, 2017 Share Posted September 20, 2017 Ah, ok I was directly copying from the field settings. It's filled with correct field names and everything Link to comment Share on other sites More sharing options...
a-ok Posted September 20, 2017 Author Share Posted September 20, 2017 54 minutes ago, abdus said: Ah, ok I was directly copying from the field settings. It's filled with correct field names and everything So was I! Which version are you on? Link to comment Share on other sites More sharing options...
abdus Posted September 20, 2017 Share Posted September 20, 2017 Latest. v3.0.75 Link to comment Share on other sites More sharing options...
Robin S Posted September 20, 2017 Share Posted September 20, 2017 3 hours ago, oma said: It turns out my line if ($event->object->name == 'home_whatson_article') { needed to be your line if ($event->object->hasField == 'home_whatson_article') { Ryan committed a change back in May in response to this issue but it hasn't been merged to the master branch yet. 2 Link to comment Share on other sites More sharing options...
a-ok Posted September 21, 2017 Author Share Posted September 21, 2017 13 hours ago, Robin S said: Ryan committed a change back in May in response to this issue but it hasn't been merged to the master branch yet. Thanks as always, Robin. That's great. 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