Jump to content

How to set dynamic $parent_id with 'getSelectablePages' instead 'findPagesCode'


update AG
 Share

Recommended Posts

Until now, I have set $parent_id in page selection fields (InputfieldPage) that have different root directories depending on the page being edited, with the following hook:

$wire->addHookAfter('InputfieldPage::findPagesCode', function($event) {
    if(substr_count($event->object->name, 'select_focus_page') > 0) {
        $page = $event->arguments('page');
        $return = $event->return;
        $parent_id = wire('input')->id;
        $event->return = wire('pages')->get($parent_id);
    }
});

Now I see in inputfieldPage.module that the function 'findPagesCode' is deprecated. We are supposed to use the 'getSelectablePages' function instead.  However: I haven't figured out how to use 'getSelectablePages' to set the $parent_id with a hook. Has anyone had more success with this?

Translated with www.DeepL.com/Translator (free version)

Link to comment
Share on other sites

Make child pages of page beeing edited selectable in a page field named: nameOfTheField

$wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) {
	if($event->object->hasField == 'nameOfTheField') {
		$event->return = $event->pages->find('parent=' . wire('input')->get->id);
	}
});

 

  • 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...