Jump to content

Page (SELF) not saved in Page Reference


NoremPload
 Share

Recommended Posts

Hi,

I try to use a page reference to make an overview site, but i cannot select (save) the page i use the field on.

-page 1
-- article 1
-- article 2
-page 2
-- article 3
-- article 4

all templates of the pages are selected in selectable templates in field definition.

i am on page 1 and i want to select page 1 as reference. i can select all pages, but if i save, all pages are there (if i select all of them) but not page 1.

anyone can help, or is this the way it should be?

 

Link to comment
Share on other sites

It turns out PW doesn't allow that.

/**
 * Return PageArray of selectable pages for this input
 * 
 * @param Page $page The Page being edited
 * @return PageArray|null
 * 
 */
public function ___getSelectablePages(Page $page) {
    // ...

    if($children && $children->has($page)) {
        $children->remove($page); // don't allow page being edited to be selected
    }

    return $children; 
}

 

Link to comment
Share on other sites

Hmm, you can forcibly add it using this hook, though, (not tested)

// site/ready.php

wire()->addHookAfter('InputfieldPage::getSelectablePages', function (HookEvent $e) {
    $e->return->add($e->arguments(0));
});

 

Link to comment
Share on other sites

On 3/20/2017 at 8:39 PM, Soma said:

Yeah because if you reference a page in it self, it would create a endless reference.

Like @Soma said, I guess this is for preventing circular references when using the field in selectors. It's better if you add it manually in your code

Link to comment
Share on other sites

  • 1 year later...

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