Steps to reproduce
(description of the proposed solution, the rationale behind it, and workarounds for people who cannot use the patch)
- Enable book module
- Create an unpublished book page
- Click the "Printer-friendly version" link
- Expected result: See print-friendly version
- 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
Comment #1
puregin commentedFeature requests / patches should go against CVS.
It would be nice to be able to configure this feature via some kind of setting.
Comment #2
he_who_shall_not_be_named commentedAs you wish. The cvs is Drupal 7.0 beta. Patch will not work there, anyway.
Comment #3
Jaza commentedThe 'status = 1' check should only be omitted for users with 'administer nodes' privileges. Other than that, this is a needed bug fix, so +1.
Comment #4
mdupontBumping 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.
Comment #5
mdupontConfirmed in 8.x-dev.
Comment #6
mdupontPatch 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)
Comment #8
mdupontUpdated version. Fixed wrong logic.
Comment #9
mdupontFixed typo.
Comment #11
mdupont#9: book_export_html-50680-9.patch queued for re-testing.
Comment #12
mdupontMissed some debug code. I guess I should have some sleep.
Comment #13
mdupontBump. Can someone review it? It is very small and increases usability.
Comment #14
mdupontAdded a test. First ever experience with Simpletest, and I don't know if it actually works. Please review.
Comment #16
mdupontHum, 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
Comment #17
mdupontComment #18
mdupontAnyone for a quick review of #12? The patch is very small, it won't take much time.
Comment #19
mdupontRe-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.
Comment #19.0
shyamala commentedupdating as per Issue summary template
Comment #20
shyamala commentedThe 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:
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:
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.
Comment #20.0
shyamala commentededited summary
Comment #21
xjmThanks @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
Comment #22
shyamala commentedThis 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();Comment #23
shyamala commentedTried 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:
option 2 throws up the below error:
Please suggest the next steps.
Comment #24
yesct commentedComment #26
readyman commentedSydney Drupalcon
Comment #27
readyman commented#19: book_export_html-50680-19.patch queued for re-testing.
Comment #28
sidharthapI 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.
Comment #29
yesct commentedIt'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.
Comment #30
star-szr@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.
Comment #31
leslieg commentedAttempted 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.
Comment #31.0
leslieg commentedupdated steps to reproduce
Comment #39
pameeela commentedUpdated 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.
Comment #40
pameeela commentedChanging version to 9.1.x.
Comment #41
mindbet commentedThis 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
Comment #42
ramya balasubramanian commentedComment #43
ramya balasubramanian commentedHi @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:
Unpublished page
Print-friendly version of unpublished pages
Print-friendly version of published pages
I can't able to reproduce on 9.1 dev. Please let me know if I miss anything
Comment #44
ramya balasubramanian commentedComment #45
ramya balasubramanian commentedComment #46
ramya balasubramanian commentedUnknowingly 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.
Comment #47
mdupontI 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!
Comment #48
ramya balasubramanian commented@mdupont,
Can you please let me know the steps to reproduce?
Comment #49
mdupontSure. This is what I did;
/book/export/html/2)/book/export/html/1in this case)Comment #50
pameeela commentedComment #51
ramya balasubramanian commentedHi @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
Comment #52
pameeela commentedThanks 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!