Kiwi Chris Posted September 6, 2019 Share Posted September 6, 2019 I'm trying to apply a custom filter on a page field within a repeater via ready.php like so: $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if ($event->object->hasField == 'bom') { $parent = $event->arguments(0)->page->getForPage(); } // Filter criteria ... } The problem is I get "Call to a member function getForPage() on null" on the line: $parent = $event->arguments(0)->page->getForPage(); Any idea what I'm doing wrong? Link to comment Share on other sites More sharing options...
Robin S Posted September 6, 2019 Share Posted September 6, 2019 6 hours ago, Kiwi Chris said: The problem is I get "Call to a member function getForPage() on null" on the line: $parent = $event->arguments(0)->page->getForPage(); This means that there is no property "page" on $event->argument(0). The first and only argument to InputfieldPage::getSelectablePages() is: @param Page $page The Page being edited This is the page that's open in Page Edit, regardless of whether the Page Reference field is inside a Repeater or not. So probably you don't need to use getForPage() in your situation. Link to comment Share on other sites More sharing options...
Kiwi Chris Posted September 6, 2019 Author Share Posted September 6, 2019 I've checked what $event->argument(0) is returning, and it actually is the page the repeater is used on, even though that page doesn't directly have the field 'bom' as that is only used in the repeater itself, so even though the repeater item is technically a page in its own right, my hook is picking up the page the repeater is on anyway. My filter seems to be working as expected now. I think the issue arose because previously I was using a pagetable instead of a repeater, but the client didn't like the presentation, and found a repeater more intuitive. The client only needs a few items, sometimes only one, so a repeater makes sense. With the pagetable, I did need to refer to the parent, and with the repeater items technically being pages, I assumed I needed to do the equivalent, but it turns out that with repeaters the page they're used on is the page returned by the hook. 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