Jump to content
DaveDev

Show children links in page reference in admin with hook

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);
  }
});

 

Share this post


Link to post
Share on other sites

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);
  }
});

 

Share this post


Link to post
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.

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By DanielKit
      Hi. I'm currently stuck at the login page in my project. Once I enter my admin username and my password and press login, nothing happens. The page just reloads. However, the URL changes from http://myipaddress/processwire to http://myipaddress/processwire/?login=1. I've checked all of my server settings, and to my knowledge, all seems to be fine there. I don't know where to go from here.. Thanks in advance!
    • By modifiedcontent
      Small annoyance: I get a horizontal scrollbar in UIkit admin area - or actually Admin Theme Boss based on Uikit 3. I tried to fix it with CSS, but had trouble isolating/targeting it and don't want to mess with module or core files. I think this issue has been reported before. Is there a recommended fix? 
    • By Robin S
      Page Reference Default Value
      Most ProcessWire core inputfield types that can be used with a Page Reference field support a "Default value" setting. This module extends support for default values to the following core inputfield types:
      Page List Select Page List Select Multiple Page Autocomplete (single and multiple) Seeing as these inputfield types only support the selection of pages a Page List Select / Page List Select Multiple is used for defining the default value instead of the Text / Textarea field used by the core for other inputfield types. This makes defining a default value a bit more user-friendly.
      Note that as per the core "Default value" setting, the Page Reference field must be set to "required" in order for the default value to be used.
      Screenshot

       
      https://github.com/Toutouwai/PageReferenceDefaultValue
      https://modules.processwire.com/modules/page-reference-default-value/
    • By codevark
      The Minimal Site works fine, but if I try to login as admin, I have no idea what the credentials are.
      I did not do the "install" process myself. The OVA came with everything set up, but there's no mention of the PW admin credentials being set to some initial value.
      Wondering if anyone else has tried the Bitnami OVA and if there's a simple answer.
      --Pete
    • By jds43
      Hello, I'm trying to list the categories, on the front through select options, that have been selected by page reference field (multiple pages PageArray) on the child pages.
      Things to Do (would only display three, six, seven, nine in select)
      -thing one (-category three, -category nine)
      -thing two (-category six, -category seven)

      Lodging (would only display one, two, three, four in select)
      -lodging one (-category one, -category two)
      -lodging two (-category three, -category four)

      Dining (would only display five, six, seven, eight in select)
      -dining one (-category five, -category six)
      -dining two (-category seven, -category eight)
      Categories(hidden page)
      -category one
      -category two
      -category there
      -category four
      -category five
      -category six
      -category seven
      -category eight
      -category nine
      -category ten
      $categories = $pages->find(1129)->children('include=hidden'); foreach($categories->references('category') as $ref) { echo $ref->title; } This selector isn't working, but it seems 'references' would be helpful. I've never used it before, so I'm not sure how to employ for this.
      https://processwire.com/blog/posts/processwire-3.0.107-core-updates/#page-gt-references
×
×
  • Create New...