BrendonKoz Posted January 27, 2023 Share Posted January 27, 2023 I know that Super Users can see hidden and unpublished pages by default. However, is it possible to force a Page Reference field to only show published, and visible pages - even for Super users? I'd like to just minimize the potential for error with a specific use-case, but can't seem to get the selector correct. I tried the following selector: status!=unpublished, status!=hidden That didn't seem to work for me. In fact that didn't work at all, even in a standard find() call. Link to comment Share on other sites More sharing options...
gebeer Posted January 28, 2023 Share Posted January 28, 2023 Your problem might be related to Autocomplete and PageListSelect inputfields not allowing for custom selector strings. See Just a guess 1 Link to comment Share on other sites More sharing options...
BrendonKoz Posted January 30, 2023 Author Share Posted January 30, 2023 It does appear as though it's related. In my instance I'm using PageListSelect which was mentioned as also being affected by this. I'll give the available solutions a try tomorrow. Thank you! 1 Link to comment Share on other sites More sharing options...
BrendonKoz Posted January 31, 2023 Author Share Posted January 31, 2023 I've not yet been able to solve this. Most of the methods I can see in the related classes are to include what isn't already included in the result. I'm trying to prevent auto-inclusion from roles that normally would automatically have access. wire/core/PagesLoader's find method, which calls findShortcut, seems to be two places where I'd need to concentrate how to work around, but I'm not sure if it's even worth it to investigate further. It might be easier to temporarily remove role-based access, but doing so within an admin template is the tougher part. The purpose is to prevent specific roles that have access to manage a specific template, to then use a page reference field (which would attempt to directly add the chosen page to primary front-end navigation) to select from an unpublished or hidden page. Link to comment Share on other sites More sharing options...
Robin S Posted January 31, 2023 Share Posted January 31, 2023 @BrendonKoz, you can use the hook below to target the children() selector used in PageListSelect/PageListSelectMultiple and remove the "status" clause that allows unpublished and hidden pages. Because those inputfields use ProcessPageList the tricky part is only affecting the inputfields and not the main page tree. After some digging I found that you can distinguish these cases by a "labelName" GET variable. $wire->addHookBefore('ProcessPageList::find', function(HookEvent $event) { $selector = $event->arguments(0); $name = $event->wire()->input->get('labelName'); if($name === 'your_page_reference_field_name') { $selector = str_replace(', status<9999999', '', $selector); $event->arguments(0, $selector); } }); Before: After: 4 Link to comment Share on other sites More sharing options...
BrendonKoz Posted January 31, 2023 Author Share Posted January 31, 2023 That is mighty impressive. I'm going to look this over more carefully later this evening, but (1)that's awesome, and (2)I was apparently looking in the completely wrong place(s). Ugh. ?♂️ Thank you so much, Robin! This will undoubtedly prove useful now, and in the future. UPDATE: It's 3 days later and I finally had an opportunity to look at this and give it a shot. I'm still lost on how Robin maneuvered through the file structure to identify where to adjust the call - that's some magic there - but I'd just like to clarify one thing: This hook doesn't allow you to target a specific template (PW conditional hooks); nor was I able to find a passed value to access the intended template (I did find a value, but when trying to access it directly, I only got a null value), so unless someone discovers how to target the intended calling page's template, this would be best for overriding only a field that is going to globally be overridden in this manner. Other than being aware of this, it works great! 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now