To reproduce (with uid=1)
- install drupal 8.1.2 (or 8.1.x-dev, or 8.2.x-dev)
- enable Book module
- place "Book navigation" block to "Sidebar first" region
- set "Show block only on book pages" on block configuration interface
- create an Article and add it as a book (on "Book Outline" fieldgroup select "Create a new book")
- save as published - it is OK
- edit created article and unpublish it (save as unpublished)
- you will got an 500 error, with message:
Recoverable fatal error: Argument 1 passed to Drupal\book\BookManager::bookTreeOutput() must be of the type array, null given, called in .../core/modules/book/src/Plugin/Block/BookNavigationBlock.php on line 168 and defined in Drupal\book\BookManager->bookTreeOutput() (line 501 of .../core/modules/book/src/BookManager.php)
So if you have "Show block only on book pages" with unpublished parent book item, you get this fatal error and you have to disable book navigation block to view/edit this node.
Comment | File | Size | Author |
---|---|---|---|
#27 | fatal_error_in_book-2743183-27.patch | 2.25 KB | szato |
#22 | fatal_error_in_book-2743183-22.patch | 2.17 KB | szato |
#20 | navigation_block_8.1.x-2743183-20.patch | 955 bytes | nielsvandermolen |
Comments
Comment #2
szato CreditAttribution: szato at Brainsum commentedComment #3
szato CreditAttribution: szato at Brainsum commentedComment #4
szato CreditAttribution: szato at Brainsum commentedComment #5
catchComment #6
dagmarComment #8
szato CreditAttribution: szato at Brainsum commentedRetest passed.
Comment #9
dawehnerLet's ensure we add the test coverage to ensure to not break it again.
Comment #10
xjm@catch, @effulgentsia, @Cottser, @alexpott, and I discussed this issue today and agreed to handle it as a major issue per https://www.drupal.org/core/issue-priority#major-bug per these points specifically:
This issue fits in those categories. If, however, it is possible for the site to end up in a completely unrecoverable state, then this issue should be repromoted to critical. Thanks!
Comment #11
dawehnerNeeds work because we need some tests :(
@szato
Feel free to ping me, if you need some help with that.
Comment #12
szato CreditAttribution: szato at Brainsum commentedComment #13
ressa CreditAttribution: ressa as a volunteer commentedI just got hit by this one... does it look like the patch will make it into the next 8.1 release, or will we have to wait for Drupal 8.2?
Comment #15
szato CreditAttribution: szato at Brainsum for Tieto commentedCore patch and new test added.
Comment #16
szato CreditAttribution: szato at Brainsum for Tieto commentedTypo fixes.
Comment #17
dawehnerNote: We don't need to logout at the end here, the site is destroyed afterwords anyway ... Let's skip that.
Comment #18
szato CreditAttribution: szato at Brainsum for Tieto commented@dawehner thank you for your review.
$this->drupalLogout(); removed from my testBookNavigationBlockOnUnpublishedBook()
Comment #19
gnugetHi @szato.
Thanks for your patch, A few nits:
It is not necessary pointing to a specific issue (unless there is a TODO there), you just need to describe what you are testing.
There is already an adminUser check:
$this->adminUser
in that class.We are mixing the old array syntax with the short syntax, usually in new methods we use the short syntax.
So, can you please change all the
array()
to[]
?I think this is not the best approach to fix this, with this patch if the top node of the book is unpublished we hide the entireI talked with Catch via IRC and he thinks to your approach is correct, so ignore this last point :-) Thanks!Book Navigation
block but if we are a user with the right permission (like an admin or if the node belongs to the user) we should be able to see this block even if the node is unpublished.Comment #20
nielsvandermolen CreditAttribution: nielsvandermolen for Open Social commentedAdding a condition for published nodes also fixes the issue for me on 8.1.x.
Comment #21
ribelI have tested patch applied by @nielsvandermolen in #20, and it fixes the issue on 8.1.x.
Comment #22
szato CreditAttribution: szato at Brainsum for Tieto commented@gnuget thank you for your review.
Modified patch added (+ typo fix, + removed unneeded permission).
Comment #23
szato CreditAttribution: szato at Brainsum for Tieto commentedComment #24
szato CreditAttribution: szato at Brainsum for Tieto commentedHi @nielsvandermolen,
your patch (navigation_block_8.1.x-2743183-20.patch) is matching to 8.2.x-dev too and also fix the issue. After applying to the core, the newly created testBookNavigationBlockOnUnpublishedBook() passes too ;)
Comment #25
gnugetlooks good to me.
Thanks!
Comment #26
alexpottThis error occurs because \Drupal\book\BookManager::doBookTreeCheckAccess() will set a tree to [] if the access is false.
One of the key parts of how we check book access is in \Drupal\book\BookManager::bookTreeCheckAccess()
So an alternative and perhaps better fix for this is to add something similar to the query in \Drupal\book\Plugin\Block\BookNavigationBlock::build(). What I'm saying is change:
to
Because whilst this query does access checks, block navigation always only display published content (never unpublished). Whether or not the users can view unpublished nodes is irrelevant. The advantage of doing the fix this way is that when this occurs we'll do way less because we wouldn't ever call the book tree building code.
The fix in #22 will work and maybe the sub-system maintainer will feel it is a better approach but I think it is worth considering the change outlined above.
In reviewing the patch I ran the test without the fix and it fails as expected - nice work on the test.
Comment #27
szato CreditAttribution: szato at Brainsum for Tieto commentedHi @alexpott, thank you for your review.
I guess you didn't notice @nielsvandermolen's solution: navigation_block_8.1.x-2743183-20.patch. He did what you suggested (+ he used:
->condition('status', NODE_PUBLISHED)
).I agree, filtering published books is a better solution, so I merged his patch and my testBookNavigationBlockOnUnpublishedBook().
I hope we have the final patch for this issue :)
Comment #28
nielsvandermolen CreditAttribution: nielsvandermolen for Open Social commentedWorks well and I think we all can agree on this solution. It seems the patch can still go in the 8.2.x branch because it is not a new feature.
Comment #29
gnugetAll the fixes land first on 8.3.x and then we can backported them to 8.2.
But Yes I agree this should be on 8.2 as well.
Thanks!
Comment #30
alexpottCommitted and pushed bcee34d to 8.3.x and 63b661d to 8.2.x. Thanks!
Eligible for 8.2.x because this is a straight up bug-fix with no new methods or possibly breaking changes. I spoke to @pwolanin about this change - he want to rewrite book module :) - he seemed okay with the change.