Jump to content

Selectable pages from parent page field


fredbob
 Share

Recommended Posts

Hi,

I have a field on a page that I am trying to set the selectable pages to the parent pages, multi page field.

-- Parent (has page field with pages I want to select from)

-- -- Child (has field that needs to be able to select pages from the parents page field)

 

I have tried using custom PHP selectors, but in the new version of processwire the custom PHP selector has been changed into a hook. I am not sure how to write it, any help would be appreciated.

 

Quote

 

Add the following hook to a /site/ready.php file and modify per your needs. The hook should find and return selectable pages in a PageArray.


$wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) {
  if($event->object->name == 'result_judge_challenge') {
    $event->return = $event->pages->find('your selector here');
  }
});

If you need to know the page being edited, it is accessible from: $event->arguments('page');

 

 

Cheers.

Link to comment
Share on other sites

I have no idea why you have such a setup but anyway, here goes. As per the instructions, your Hook needs to return a PageArray. This is untested:

$wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) {
  if($event->object->name == 'result_judge_challenge') {
	$page = $event->arguments('page');	
	$event->return = $page->parent->parent_multi_page_field;// this should return a PageArray
  }
});

You might want to add checks to see if the parent page actually has items in its page field.

Edited by kongondo
  • Like 4
Link to comment
Share on other sites

  • 2 months later...

Hello @LostKobrakai.

As documented for custom selectors for PW 3+:

<?php
$wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) {
    if($event->object->name == 'ticket') {
        $page = $event->arguments('page');
        $result = $page->parent()->parent()->children('template=event-tickets')->children();
        print_r($result);
        $event->return = $result;
    }
});

This selection happens from within a Registration. See example structure here: 

structure.thumb.jpg.527275e47c9d4b02a89b6b7e5168d5b0.jpg

Thank you already!

Link to comment
Share on other sites

// Page > Page > Page > PageArray > children()
// There's no PageArray::children() method
$result = $page->parent()->parent()->children('template=event-tickets')->children();

// Use this:
$result = $page->parent()->parent()->child('template=event-tickets')->children();

// Or even
$event = $page->closest('template=event');
$tickets = $pages->find('has_parent=$event, parent.template=event-tickets');

 

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