Jump to content

custom field to select unpublished pages - selectable but doesn't save selection


wes
 Share

Recommended Posts

Hi All!

Quick preface just to explain my reasoning behind what I'm trying to make: I have a web portfolio with a bunch of projects. Some I want to keep as unpublished for archival purposes, not viewable by the public. But sometimes I will want to email a potential client with a guest user/pass and have them gain access to these unpublished pages (that I specifically curate per-user) through the normal project listing template. I didn't want to use hidden pages in case they tried to share the URL with someone else.

Stage 1 of my idea to accomplish this is add a new field to the system user template (called special_pages). I set the field type to page and set a custom selector on it that works great in terms of displaying pages for selection (status=unpublished, template=work). However, when I select a few pages using any multi page select UI and click "save" it doesn't actually save my selection when I reload the user page. If I change the selector I can successfully save normal pages.

Any ideas? If it helps reach a solution, stage 2 of my idea was to write a module that hooked Page::viewable and checked if the logged-in user had the page selected in this field on their user page. Haven't really messed around with that yet since I'm stuck on this first part.

Link to comment
Share on other sites

Hi Wes,

Try, "allow unpublished pages" under advanced options when editing the page field

Edit 1:

My bad; that's only in the dev version..but it's throwing up errors anyway...testing some more

Edit 2:

If I use normal page selection (without custom selector) it works and allows selection and saving of unpublished pages. If I use a custom selector on the Page Ref Field, I get the WireException/error Page $value is not valid for $field->name (line 359 of FieldtypePage.module). Hmmm, strange..

Edited by kongondo
  • Like 1
Link to comment
Share on other sites

I appreciate that you're looking into this, kongondo. Looks like I may have to figure out another way of achieving this if this issue is still being worked on in the dev branch. Will keep my fingers crossed though

Link to comment
Share on other sites

There's a note in source that custom code doesn't yet work with the validPage check.

However, in my quick test you can still use it to select unpublished page via normal parent/template config and using PageListSelect or PageListSelectMultiple.

  • Like 1
Link to comment
Share on other sites

Aah, I missed that note in the source. Yes, as I stated above, unpublished page selection via normal method worked for me too ;) - even with AsmSelect and autocomplete , checkboxes and SelectMultiple..

Edited by kongondo
Link to comment
Share on other sites

Ye

Are you both still referring to the dev version? I tried it with 2.3.0 (template restriction on Page field, SelectMultiple UI type), and I can't see/select the unpublished pages.

Yes...the note Soma referred to is in the dev source code :)....I believe...(since allow unpublished pages is only in the dev atm)

Edited by kongondo
  • Like 1
Link to comment
Share on other sites

@Soma
 
about the note,  are you referring to findPagesCode? Isn't the above about findPagesSelector which seems to have been implemented?
 
Edit:
 
You are right, as usual Soma :D

// build a selector to find matching pagerefs 
// @todo should $selector include check_access=0 or even include=all?
$selector = 'include=hidden, ';
if($field->findPagesSelector) $selector .= $field->findPagesSelector . ", ";
if($field->parent_id) $selector .= "parent_id={$field->parent_id}, ";
if($field->template_id) $selector .= "templates_id={$field->template_id}, ";
// @todo note $field->findPagesCode is not implemented
 

Yes, the above post by Wes is about findPagesSelector but the $selector is currently limited to include=hidden rather than include=all (to include unpublished pages) as can be seen on line#559....Unless I am looking at the wrong code? ;)

Edited by kongondo
Link to comment
Share on other sites

I'm thinking this change might be a good idea there?

// build a selector to find matching pagerefs 
// @todo should $selector include check_access=0 or even include=all?
$selector = 'include=hidden, ';
if($field->findPagesSelector) {
  // remove the existing include=hidden, only if selector specifies a different include=something
  if(strpos($field->findPagesSelector, 'include=') !== false) $selector = '';
  $selector .= $field->findPagesSelector . ", ";
}
  • Like 1
Link to comment
Share on other sites

I've just tried changing FieldtypePage module as per Ryan's post (and then changed my custom field selector to template=work,include=all), but I still can't save the unpublished pages I selected from the Page field-- they appear, but after saving my selection, the user page reloads and there are no selected pages within the field.

It seems the issue is not with displaying/querying unpublished pages to display within the Page field (that worked before with status=unpublished). Something happens between selecting the pages within the field, submitting the form, and ProcessWire deciding whether or not the unpublished pages submitted for the field are valid as input or not.

Am I just completely missing what people are talking about in this thread? I feel a little confused about the conversation, heh...

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