Display BookNavigationBlock when book root node is unpublished

Created on 8 November 2021, over 2 years ago
Updated 1 May 2024, about 2 months ago

Problem/Motivation

On a site with many large and complex books, it can be desirable for authors to view the book navigation, even if the book has not been published yet.

In #2743183: Fatal error in Book navigation block for unpublished parent book item β†’ , an EntityQuery was added to \Drupal\book\Plugin\Block\BookNavigationBlock::build() to verify that the book root node exists, that the current user has access to it, and that the book root is published. This change replaced older code that simply verified that the book root node existed. Later, in #3207961: EntityQuery accessCheck: additional cases where accessCheck needs specifying β†’ , the EntityQuery was modified to check that the user has access to the book root node.

The condition to exclude unpublished book pages was added in #2743183: Fatal error in Book navigation block for unpublished parent book item β†’ to prevent an issue where unpublished book root nodes could occasionally cause \Drupal\book\BookManager::bookTreeAllData() to return an empty array, which would in turn pass NULL as the first parameter to \Drupal\book\BookManager::bookTreeOutput(), which violated that argument's type declaration, leading to a recoverable fatal error.

However, if I remove the condition that the book root must be published from BookNavigationBlock::build() and follow the steps to reproduce in #2743183: Fatal error in Book navigation block for unpublished parent book item β†’ , I can no longer reproduce the error... I think this is because there was a similar EntityQuery in \Drupal\book\BookManager::bookTreeCheckAccess() that was removed in 9.1.x in #26552: Allow users with access to unpublished nodes to create unpublished books β†’ . In other words, I think it's safe to, once again, allow the BookNavigationBlock to display when the book root node is unpublished.

Proposed resolution

In the EntityQuery which verifies that the current user has permission to view the book root (in \Drupal\book\Plugin\Block\BookNavigationBlock::build()), remove the condition that the book root must be published.

Turns out this wasn't necessary.

Remaining tasks

  1. Review and feedback
  2. RTBC and feedback
  3. commit

User interface changes

Book Navigation block will appear when viewing a book whose parent node is not published.

API changes

None.

Data model changes

None.

Release notes snippet

To be determined.

✨ Feature request
Status

Needs work

Version

1.0

Component
BookΒ  β†’

Last updated 2 days ago

  • Maintained by
  • πŸ‡ΊπŸ‡ΈUnited States @pwolanin
Created by

πŸ‡¨πŸ‡¦Canada alireza.tayari Ontario

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024