Jump to content

[SOLVED] How to setup the selectable pages in a Page Reference Field inside a Repeater?!


Pixrael
 Share

Recommended Posts

I have a Page Reference Field and I need to select only the children pages of the current page where the field is edited. But the problem here is that the field is inside a Repeater, and the repeaters are actually another pages in the tree.. so where I can do easily using a custom code in ready.php like this:

$wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) {
  if($event->object->hasField == 'page_list') {
    $event->return = $event->arguments('page')->children;
  }
});

this don't work If the field is inside a Repeater.. I need to get the related page to the current repeater page to get the children, but how to do it?

Link to comment
Share on other sites

I try it but in the Field setting page I get this error:

ProcessField: Method Page::getForPage does not exist or is not callable in this context

and in the Page edit i get this: 

InputfieldRepeaterMatrix: Repeater 'layouts_main' preload 'page_list': Method Page::getForPage does not exist or is not callable in this context

Link to comment
Share on other sites

This one seems to work for me. 

$wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) {
    if($event->object->hasField == 'page_list') {
        $event->return = $event->object->hasPage->children;
    }
});

Edit:

Nope. ->hasPage gives the repeater item page (not exactly, keep reading), ->arguments('page') gives the page being edited.

$this->addHookAfter('InputfieldPage::getSelectablePages', function (HookEvent $e) {
    if ($e->object->hasField->name != 'testReference') return;
    $e->return = $e->arguments('page')->children;
});

Weird thing is that InputfieldPage::getSelectablePages is called twice for every new repeater item. On the first call, hasPage and arguments('page') are identical, but on the second call, hasPage is the repeater item, arguments('page') is the page being edited.

So using the argument seems to be the better option.

Edited by abdus
  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...