Jump to content

'Page Reference' field overrides


a-ok
 Share

Recommended Posts

I have a 'Page Reference' field that I use for internal links. The default selectable pages for this field, is 'selector string' with the content `template=home, sort=sort`. This is just a filler as what I'm doing is setting overrides for the 'Details: Page field value type', 'Input: Input field type' and 'Input: Selector string' options within the template view so the fields returned are contextual.

However, upon doing this I get this error when trying to save one of the pages that has the field with different options

`PagesEditor: Error saving field "linkInternal" - Page 1079 is not valid for linkInternal (Page 1079 does not match findPagesSelector: template=home, sort=sort, id=1079)`

Any thoughts? Is this not possible? I guess I could use hooks but thought this method at least kept the changes together.

Link to comment
Share on other sites

I've read your post now three times, and I'm still not sure what you try to achieve.

Your selector is basically useless, since there can only be one page with template=home. (and sorting one single page is... useless too)

Did you mean has_parent=home?

Link to comment
Share on other sites

28 minutes ago, dragan said:

I've read your post now three times, and I'm still not sure what you try to achieve.

Your selector is basically useless, since there can only be one page with template=home. (and sorting one single page is... useless too)

Did you mean has_parent=home?

Sorry!

The template=home part is just the default I set (I guess this could be in theory just be blank) but it’s the fact that after changing the selector to something else contextually within a template using the overrides it still looks to the one set as the field default (whereas it shouldn’t)

Link to comment
Share on other sites

How are you overriding the selectable pages with contextual options? I have recently used a similar approach to have a different set of categories selectable depending on a page's position in the page tree. The error you mentioned will definitely occur if you aren't hooking getSelectablePages during the request that saves the page.

For reference, here is my code that is working for me (this is for a multisite, so $homepage is the current multisite instance):

$wire->addHookAfter('InputfieldPage::getSelectablePages', function (HookEvent $event) {
    if ($event->object->hasField->name === 'category') {
        $currentPage = $event->arguments('page');
        $homepage = $currentPage->rootParent;
        $categories = $homepage->get('template=category-index, include=hidden')->children('template=category');
        $event->return = $categories;
    }
});

 

Link to comment
Share on other sites

Oh I see, that's easier of course ^^ In that case, two suggestions:

  • Have you tried setting the default value for the Selector string to something more permissive so that it allows all pages? Not sure why the overwrite is not working, but this could be a workaround.
  • Can you use separate fields for each context? I'd usually only re-use fields if they have the same function within different contexts, though that is of course only personal preference.

@dragan You can allow overrides for pretty much any field setting if you use advanced mode. Not all overrides are really stable though, I guess this is one of those cases.

Link to comment
Share on other sites

21 minutes ago, MoritzLost said:
  • Have you tried setting the default value for the Selector string to something more permissive so that it allows all pages? Not sure why the overwrite is not working, but this could be a workaround.
  •  

This is a decent call. I could even write a hook to include all pages (unless I can do this with a selector) and then use the override then it'll only showing options from all pages. That'll work!

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