Steps to reproduce

(description of the proposed solution, the rationale behind it, and workarounds for people who cannot use the patch)

  1. Enable book module
  2. Create an unpublished book page
  3. Click the "Printer-friendly version" link
  4. Expected result: See print-friendly version
  5. Actual result: Empty white page

This issue exists in core Book module Drupal 7 & Drupal 8
No need for contributed module. The printer-friendly feature exists in core book module.

Remaining tasks

Patch at: http://drupal.org/node/50680#comment-4715114 not correct, need to write tests and fix the same.

Original report by [he_who_shall_no...]

This patch is for users who don't want to see an empty page when they click on the "printer-friendly version" link (unpublished/not in moderation queue book pages).

Comments

puregin’s picture

Version: 4.6.5 » x.y.z

Feature requests / patches should go against CVS.

It would be nice to be able to configure this feature via some kind of setting.

he_who_shall_not_be_named’s picture

As you wish. The cvs is Drupal 7.0 beta. Patch will not work there, anyway.

Jaza’s picture

Version: x.y.z » 6.x-dev
Category: feature » bug
Status: Needs review » Needs work

The 'status = 1' check should only be omitted for users with 'administer nodes' privileges. Other than that, this is a needed bug fix, so +1.

mdupont’s picture

Title: In unpublished book pages the "printer-friendly version" doesn't work » "printer-friendly version" of unpublished book pages is blank
Version: 6.x-dev » 7.x-dev
Status: Needs work » Active

Bumping to D7. The same bug is still present in Drupal 6 AND Drupal 7.

To reproduce:
- log in with a user (other than #1) with permissions "access printer-friendly version" and "administer nodes" (D6) or "view own unpublished nodes" (D7)
- create a new book page in whatever book, save it but don't publish it
- click on the link "printer-friendly version"
- the destination page is empty

Cause:
book_export_html() calls book_menu_subtree_data(), which in turn calls menu_tree_check_access(). The latter makes a DB query which checks for status = 1. In consequence, unpublished nodes are removed from the result set, so the export page comes empty. In D6 and D7 these functions are virtually identical.

Expected behavior:
Users that are able to access an unpublished book page should be able to display its printer-friendly version. It would require to edit book_export_html() not to rely on book_menu_subtree_data(), but a function which do not call menu_tree_check access() in the end.

At the very least, an error or explanation message should be displayed instead of a completely blank page.

mdupont’s picture

Version: 7.x-dev » 8.x-dev

Confirmed in 8.x-dev.

mdupont’s picture

Status: Active » Needs review
StatusFileSize
new1.07 KB

Patch attached. It fixes the 2 main UX problems in a simple way :
- when a book node is unpublished, the link to "Printer-friendly version" is now hidden (to be consistent with "Add child page" link behavior)
- when trying to access the printer-friendly version of an unpublished book node, we get an access denied (which is really what is happening)

Status: Needs review » Needs work

The last submitted patch, book_export_html-50680-6.patch, failed testing.

mdupont’s picture

Status: Needs work » Needs review
StatusFileSize
new1.15 KB

Updated version. Fixed wrong logic.

mdupont’s picture

StatusFileSize
new1.65 KB

Fixed typo.

Status: Needs review » Needs work

The last submitted patch, book_export_html-50680-9.patch, failed testing.

mdupont’s picture

Status: Needs work » Needs review

#9: book_export_html-50680-9.patch queued for re-testing.

mdupont’s picture

StatusFileSize
new1.15 KB

Missed some debug code. I guess I should have some sleep.

mdupont’s picture

Bump. Can someone review it? It is very small and increases usability.

mdupont’s picture

StatusFileSize
new3.52 KB

Added a test. First ever experience with Simpletest, and I don't know if it actually works. Please review.

Status: Needs review » Needs work

The last submitted patch, book_export_html-50680-13.patch, failed testing.

mdupont’s picture

Status: Needs review » Needs work

Hum, it is not so simple to write tests... Please dicard the patch in #14 and review the one in #12.

If you have experience writing tests feel free to help here, as I won't be able to do it myself. I think 2 additional tests are needed:
- make sure an unpublished book node doesn't have a link to the printer-friendly version
- make sure trying to access the printer-friendly version of such a node returns access denied

mdupont’s picture

Status: Needs work » Needs review
mdupont’s picture

Status: Needs work » Needs review

Anyone for a quick review of #12? The patch is very small, it won't take much time.

mdupont’s picture

StatusFileSize
new1.15 KB

Re-rolled against D8.

As a reminder, this patch will throw a drupal_access_denied() whenever trying to access the print version of an unpublished book page, as it goes through the menu system, which do not give access to unpublished nodes (see comment #4 for more info).

Without this patch, the page comes blank without any explanation, so it is better to have an Access Denied which reflects what is really happening.

shyamala’s picture

Issue summary: View changes

updating as per Issue summary template

shyamala’s picture

Issue tags: -Needs tests

The patch doesnot work. The path needs to include path core. Moreover What the patch does is checks if the node is published before the printer-friendly version link is added.
Code as in current patch:

@@ -100,7 +100,7 @@ function book_node_view_link($node, $view_mode) {
         );
       }
 
-      if (user_access('access printer-friendly version')) {
+      if (user_access('access printer-friendly version') && $node->status == 1) {
         $links['book_printer'] = array(
           'title' => t('Printer-friendly version'),
           'href' => 'book/export/html/' . $node->nid,

But what we need to achieve to change the access arguments of the book/export/%/% menu call back from "access printer-friendly version" to an access callback _book_printer-friendly_access that is based on "access printer-friendly version" and node permissions. This change will be similar to how book outline permissions are defined. Add the below code:

 $items['book/export/%/%'] = array(
    'page callback' => 'book_export',
    'page arguments' => array(2, 3),
    'access callback' => '_book_printer-friendly_access',
    'access arguments' => array(1),
    'type' => MENU_CALLBACK,
    'file' => 'book.pages.inc',
  );
function _book_printer-friendly_access(Node $node) {
  return user_access('access printer-friendly version') && node_access('view', $node);
}

With this above permission check the access check in book_export_html, book.pages.inc is redendant and can be removed. Code currently in book.pages.inc We need to be able to display the printer friendly content for users with permissions to view the unpublished node.

shyamala’s picture

Issue summary: View changes

edited summary

xjm’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Thanks @Shyamala! Tagging for a test, which should help us test different solutions. The test should fail when the bug is present and pass when combined with the patch. Upload a test-only patch followed by a combined patch

shyamala’s picture

StatusFileSize
new2.31 KB

This is a work in progress test patch. I not sure how to create a book node that is unpublished...

Need to understand how to make the book unpublished while we create. The code used to create a book in this patch is:
$nodes = $this->createBook();

shyamala’s picture

Issue tags: +Needs tests
StatusFileSize
new3.74 KB
new3.83 KB

Tried 2 approaches to create an unpublished book node.

1) edited status in the form
2) tried to save the node object (this approach is similar to that used in node module)

option 1 throws up the below error:

Error Message for array status($edit['status'] = $status):

An AJAX HTTP error occurred. HTTP Result Code: 200 Debugging information follows. Path: /drupal8/batch?id=65&op=do_nojs&op=do StatusText: OK ResponseText: Fatal error: Call to a member function label() on a non-object in /var/www/drupal8/core/modules/book/lib/Drupal/book/Tests/BookTest.php on line 197

option 2 throws up the below error:

Error Message for object status($node->status = $status):

An AJAX HTTP error occurred. HTTP Result Code: 200 Debugging information follows. Path: /drupal8/batch?id=66&op=do_nojs&op=do StatusText: OK ResponseText: Fatal error: Call to undefined method stdClass::save() in /var/www/drupal8/core/modules/book/lib/Drupal/book/Tests/BookTest.php on line 238

Please suggest the next steps.

yesct’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, book_status_object.patch, failed testing.

readyman’s picture

Assigned: Unassigned » readyman

Sydney Drupalcon

readyman’s picture

Status: Needs work » Needs review

#19: book_export_html-50680-19.patch queued for re-testing.

sidharthap’s picture

I tried this test. i found that we can not use $node->label() while fetching the node from database.
I removed $node->label() with $node->title and the test excutes for me. I think this is a issue with book module using $node->label() .
So first we should fix the book module issue after that this test.

yesct’s picture

Assigned: readyman » Unassigned

It's been a while @readyman.
If you want to work on the patch, just assign it back to you.

Otherwise I think this is available for anyone.

star-szr’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

@sidharthap - were you able to find an issue about the book module using $node->label()? It's not clear to me what the next steps here are or if this issue should be postponed on another bugfix.

An issue summary update would be great.

leslieg’s picture

Status: Needs work » Postponed (maintainer needs more info)

Attempted to reproduce the issue on a new Drupal 8 site (simplytest.me drupal core 8.0-alpha2) with the Book module enabled. Both users in the Steps to Reproduce in the issue summary need to have the permission "node test view" enabled. I cannot find that permission in the D8 site with only core modules installed. Also searched Drupal.org and Google with no success.

leslieg’s picture

Issue summary: View changes

updated steps to reproduce

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

pameeela’s picture

Title: "printer-friendly version" of unpublished book pages is blank » "Printer-friendly version" of unpublished book pages is blank
Priority: Normal » Minor
Issue summary: View changes
Status: Postponed (maintainer needs more info) » Active
Issue tags: +Bug Smash Initiative
Related issues: +#26552: Allow users with access to unpublished nodes to create unpublished books

Updated issue summary to reflect that I was able to reproduce the blank print version. I removed the secondary issue mentioned because it wasn't totally clear but in testing I got Access denied when trying to view the printer-friendly version as a user with minimal permissions, which seems like the correct outcome.

Changed priority to minor given that this issue is related to previewing unpublished content and has not been chased up at all lately.

pameeela’s picture

Version: 8.8.x-dev » 9.1.x-dev

Changing version to 9.1.x.

mindbet’s picture

This issue is resolved by the patch at:

https://www.drupal.org/files/issues/2020-03-18/26552-156.patch

Steps to reproduce:

- Install Drupal 9.0.1
- Create example book, with several published and unpublished pages
- Attempt to load printer-friendly version of an unpublished page and you will see a blank page
- Apply patch https://www.drupal.org/files/issues/2020-03-18/26552-156.patch
- After applying patch, printer-friendly version of unpublished page loads correctly

ramya balasubramanian’s picture

Assigned: Unassigned » ramya balasubramanian
ramya balasubramanian’s picture

Hi @mindbet, @pameela,

I have taken the Drupal 9.1 dev and enabled the books module. Then I have created some sample book pages and assign that to books. Then when I click the 'Print-friendly-version' of unpublished book pages, I am not getting any blank page. Without applying the above patch, it is working fine in 9.1 dev. Please see the below screenshots.

Book Screen:

test

Unpublished page

test

Print-friendly version of unpublished pages

test

Print-friendly version of published pages

test

I can't able to reproduce on 9.1 dev. Please let me know if I miss anything

ramya balasubramanian’s picture

Assigned: ramya balasubramanian » Unassigned
ramya balasubramanian’s picture

Status: Active » Needs review
ramya balasubramanian’s picture

Status: Needs review » Active

Unknowingly I have changed the status, Since there is no patch to test I am moving this back to 'Active' till the reporter of this issue comes back and check.

mdupont’s picture

I tested against the HEAD of 9.1.x branch and contrary to what @ramya-balasubramanian got, I still get blank pages for printer version of unpublished book pages.

However, I confirm that the patch at #26552-156: Allow users with access to unpublished nodes to create unpublished books fixes the issue!

ramya balasubramanian’s picture

@mdupont,

Can you please let me know the steps to reproduce?

mdupont’s picture

Sure. This is what I did;

  1. Check out the latest commit from 9.1.x branch (I used DDEV to run it)
  2. Install a clean standard Drupal
  3. Log in as admin
  4. Enable the Book module
  5. Create a new Book page, making sure that it will create a new book ("Book Outline" panel in the sidebar)
  6. Create another book page, making it a child page in the first book
  7. Unpublish the 2 book pages
  8. Visit the child page and click on the "Printer-friendly version" link (which goes to /book/export/html/2)
  9. The page should be blank
  10. Apply the patch at #26552-156: Allow users with access to unpublished nodes to create unpublished books
  11. Clear the caches for good measure
  12. Reload the page
  13. The content should now be visible in the page
  14. It also works for the parent book page (/book/export/html/1 in this case)
pameeela’s picture

ramya balasubramanian’s picture

StatusFileSize
new246.3 KB

Hi @mdupont, @pameela

I have installed a new drupal instance and checked this 'admin/structure/book' path, there we will not find any unpublished content listing as per this issue(https://www.drupal.org/project/drupal/issues/1184692). That time when we click the un-published content from this path 'http://localhost:8888/book/drupal-9.1.x-dev/admin/content' it is coming as a blank page only.

Then if we remove the status from the BookManager.php (Refer this patch https://www.drupal.org/files/issues/2020-06-19/list-of-books-unpublished...), then the unpublished contents will be listed out in that path. Then if we click 'View operations' it is working fine. Please see the screenshot below.

I think if we merge this issue (https://www.drupal.org/project/drupal/issues/1184692), this problem will be solved. Please have a look and let me know if there are any issues with this idea.


After removing status from BookManager.php

tets

pameeela’s picture

Status: Active » Closed (duplicate)

Thanks mdupont and Ramya Balasubramanian! I have confirmed the patch in #26552: Allow users with access to unpublished nodes to create unpublished books resolves this too so will close as duplicate. I have also transferred credit to that issue for all who have contributed to this one.

Thanks everyone!