Jump to content
Kiwi Chris

Custom Filter on FieldtypePage in repeater producing error

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...