Jump to content

Show children links in page reference in admin with hook


DaveDev
 Share

Recommended Posts

I want the admin to select one of the child of a parent in "page reference" as radio buttons, but it comes out empty

here is my hook in site/ready.php

$wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) {
  if ($event->object->hasField == 'childLinks') {
    $page = $event->arguments('page');
    $parent = "parent=" . $page->path;
    $event->return = $event->pages->find($parent);
  }
});

 

Link to comment
Share on other sites

  • 4 months later...

Maybe a bit late, but this works for me:

$wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) {
  if($event->object->hasField == 'childLinks') {
    $currentPage = $event->arguments('page');
    $parent = "parent=" . $currentPage->id;
    $event->return = $event->pages->find($parent);
  }
});

 

Link to comment
Share on other sites

Maybe you can do the same without hooks using option "Selector string" inside settings for page reference field:

Example 1:

- Some page tree:
-- Link items
---- link-item 1
---- link-item 2
---- link-item 3
-- Page 1 with page reference field
-- Page 2 with page reference field
-- Page 3 with page reference field

Example 2:

- Some page tree:
-- link-item 1
-- link-item 2
-- link-item 3
-- Page 1 with page reference field
-- Page 2 with page reference field
-- Page 3 with page reference field

// selector string
has_parent=page.rootParent,template='link-item'

Example 3:

- Some page tree:

-- Page 1 with page reference field
---- child link-item 1
---- child link-item 2
---- child link-item 3

-- Page 2 with page reference field
---- child link-item 1
---- child link-item 2
---- child link-item 3

// selector string
parent=page,template='link-item'

Regards.

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

×
×
  • Create New...