Jump to content

Page Reference field - unpublished pages showing up in frontend


jonatan
 Share

Recommended Posts

Hi! 😄

SITE SETUP / DESCRIPTION:

What? Online art magazine with an "All featured works" and also an "All featured artists" index page, and also individual "Work" and "Artists" pages, and data relations between the different artists and their artworks.

So, I have two different page reference fields, connected by @Robin S's awesome Connect Page Fields module (though that has nothing to do with the issue in fact, Robin's plugin works great! and the issue is the same with or without it).

The two Page Reference type fields are called "works" and "artists". They are meant to simply connect different artists to different artworks.

Fx:
Work 1  (page)  –> artists (Page Reference field) : Artist A (page)           --->>> (automatically connected)         Artist A (page)  –> works (Page Reference field) : Work 1 (page)
Work 2  (page) –> artists (Page Reference field) Artist B  (page)           --->>> (automatically connected)         Artist B (page)  –> works (Page Reference field) : Work 2 (page)

ISSUE:

On both Page Reference fields, both on "artists" and on "works" this option "Allow unpublished pages" is activated:

1851594620_Skrmbillede2020-04-24kl_14_46_38.thumb.png.0dbfdc6787234dc4fb6a58adad6fb4d6.png

As it says in the option description, supposedly, unpublished pages should be selectable in the page reference field, but they should not be visible, they shouldn't appear, on the front-end...

Frontend:
To show all works related to the artist on the artist individual page I'm doing this:

<?php
foreach($page->works as $item) {      
	echo "<img src='{$item->image->first->width(200)->url}' class='pr-2'><a class='pr-4' href='$item->url'>$item->title</a>";
}

The problem is now, unexpectedly, if some work is set to "Unpublished", it shows up anyways!

WORKAROUND:

So to get around this I figured out that I can do this:

<?php
foreach($page->works as $item) {
	if($item->is(Page::statusUnpublished)) { 
		return;
	};    
	echo "<img src='{$item->image->first->width(200)->url}' class='pr-2'><a class='pr-4' href='$item->url'>$item->title</a>";   
}

But ofc this is a rather inelegant "solution" which shouldn't really be necessary, right? 

I might be missing something basic here, but really can't figure out what it is... I hope one of you awesome guys can help me out 😊

Thanks a lot in advance!

All the best,
Jonatan

Link to comment
Share on other sites

15 minutes ago, jonatan said:

The problem is now, unexpectedly, if some work is set to "Unpublished", it shows up anyways!

Just confirming that you are not inadvertently checking this whilst still logged in (as a supersuser)? :-).

Link to comment
Share on other sites

10 minutes ago, kongondo said:

Congratulations! you've found a bug :-).

Yaaaay! Horray! That's my first! 🏆🎉🐞😊

And thanks so much for such instant and helpful reply @kongondo! Still continiusly amazed by this great forum and the amazing people behind the PW community! 

 

I'll go file it 😊

Take care! And have a great weekend! 

All the best, 

Jonatan 

  • Like 4
Link to comment
Share on other sites

  • 3 months later...
6 hours ago, uiui said:

Is there a way to bring this buggy behaviour back? 😉

In other words: How can I get a page reference field to return unpublished references for the frontend?

Same as above, inverting the logic:

<?php
foreach($page->works as $item) {
	if($item->is(Page::statusUnpublished)) { 
		// do whatever
	};    
	continue;
}

 

Link to comment
Share on other sites

My problem is that the page reference field that contains the unpublished pages doesn't return any pages.

$p = $pages->get(1470);
echo count($p->galleries);

This prints 0, although galleries contains one page reference. That seemed to be different in 3.0.132.

Link to comment
Share on other sites

On 8/24/2020 at 12:47 AM, uiui said:

In other words: How can I get a page reference field to return unpublished references for the frontend?

Ryan's comment in the fixed GitHub issue:

Quote

But I don't think they should be showing up in the formatted value at all, per your issue report, so I think that's the correct behavior. They should continue appearing in the unformatted front-end value though.

Therefore, to include unpublished pages you must get the unformatted value of the field:

$items = $page->getUnformatted('your_page_reference_field_name');

 

  • Like 3
  • Thanks 1
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.
  • Similar Content

    • By kalimati
      I have a template for courses for a website on training.  Within the template I use a multiselect page reference field to define attributes associated with the course. While rendering the page I want search for a combination of attributes -in the multiselect page reference field - presence and absence of some of them -- and perform an operation accordingly. How do I search for a combination of values in the multiselect page reference field? Thanks.
      Here is the pseudo code:
      if ($page->pageReferenceField->has("title=one|two") && $page->pageReferenceField->doesnothave("title=three")) { echo ...; }  
    • By Rossie
      Hi Everyone,
      I wish to display a gallery of images from multiple pages on the site.  These images have custom fields created through page reference called 'furniture_list_type'.  Each image now has a radio button which has been selected.
      In  the example code below all images appear from the "gallery20", however the selector  "gallery20.furniture_list_type=3390" does not have any effect.  "3390" is the id of the page reference "chair" selected through the page reference.  I wish only images selected as chair to show.
      Hope someone can help with this.
       
      Thanks,
       
      Calum
       
      $imagePages = $pages->find("template=makers-child, gallery20.furniture_list_type=3390") ;                     foreach($imagePages as $p) {     echo "<ul>";     foreach($p->gallery20 as $image) {         echo "<li><img src='{$image->url}'>{$image->furniture_list_type}</li>";     }     echo "</ul>";      }
    • By JeevanisM
      HI,
      The scenario is,  I manage a magazine website, I have an article to publish, but before making it public available, I have to show the preview to my Editor and get approval. What I have done is, I created the page, filled the contents then put it as a Unpublished status. I as admin can see the preview of the page but when I send this page link to the editor ( he has no admin access, he should not because the person may vary with each articles ) , the editor cannot view the preview of Unpublished page. Is there any workaround on this ?  Is it possible to make this preview page watchable with a direct link ?


      thanks
    • By dfile
      Hello, i must count products per category like so:
      category 1 (4 products)
      --category 1.1 (2 products)
      ----category 1.1.1 (1 product)
      and so on.
      category 1 --category 1.1 ----category 1.1.1 ----category 1.1.2 ----category 1.1.3 --category 1.2 ----category 1.2.1 ----category 1.2.2 ----category 1.2.3 produkts have page references for the categories:
      product 1 -- page reference->category 1.1.1 -- page reference->category 1.1.3 -- page reference->category 1.2.2 -- page reference->category 1.2.3 what is the best way to do this, i have many categories and many many products.
      Thank you.
       
    • By snck
      Hey there,
      for a client website I need to implement a "reviewer" role. "Reviewers" should be able to review new (unpublished) articles to give feedback to editors, but not have the permission to change them. 
      I built a new "reviewer" role that only has page-view permissions for the respective templates, but this permission does not include viewing unpublished pages. How can I grant them access to the unpublished articles without giving them page-edit permission?
      Cheers,
      Flo
×
×
  • Create New...