Commit bcee34db authored by alexpott's avatar alexpott

Issue #2743183 by szato, nielsvandermolen: Fatal error in Book navigation...

Issue #2743183 by szato, nielsvandermolen: Fatal error in Book navigation block for unpublished parent book item
parent 24f816a1
......@@ -156,9 +156,12 @@ public function build() {
}
}
elseif ($current_bid) {
// Only display this block when the user is browsing a book.
$query = \Drupal::entityQuery('node');
$nid = $query->condition('nid', $node->book['bid'], '=')->execute();
// Only display this block when the user is browsing a book and do
// not show unpublished books.
$nid = \Drupal::entityQuery('node')
->condition('nid', $node->book['bid'], '=')
->condition('status', NODE_PUBLISHED)
->execute();
// Only show the block if the user has view access for the top-level node.
if ($nid) {
......
......@@ -752,4 +752,29 @@ public function testHookNodeLoadAccess() {
$this->assertEqual($book_node->book['bid'], $this->book->id());
}
/**
* Tests the book navigation block when book is unpublished.
*
* There was a fatal error with "Show block only on book pages" block mode.
*/
public function testBookNavigationBlockOnUnpublishedBook() {
// Create a new book.
$this->createBook();
// Create administrator user.
$administratorUser = $this->drupalCreateUser(['administer blocks', 'administer nodes', 'bypass node access']);
$this->drupalLogin($administratorUser);
// Enable the block with "Show block only on book pages" mode.
$this->drupalPlaceBlock('book_navigation', ['block_mode' => 'book pages']);
// Unpublish book node.
$edit = [];
$this->drupalPostForm('node/' . $this->book->id() . '/edit', $edit, t('Save and unpublish'));
// Test node page.
$this->drupalGet('node/' . $this->book->id());
$this->assertText($this->book->label(), 'Unpublished book with "Show block only on book pages" book navigation settings.');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment