Jump to content

Recommended Posts

Posted

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.

Posted

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?

Posted
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)

Posted

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

 

Posted
1 hour ago, MoritzLost said:

How are you overriding the selectable pages with contextual options?

Just using the Overrides tab per field:

 

Screenshot 2020-03-02 at 14.32.13.jpg

Screenshot 2020-03-02 at 14.32.36.jpg

Posted
14 minutes ago, a-ok said:

Just using the Overrides tab per field:

 

Interesting. I don't even see that override option...

Posted

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.

Posted
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!

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.
×
×
  • Create New...