Issue #2743183 by szato, nielsvandermolen: Fatal error in Book navigation block for unpublished parent book item

8.3.x
Alex Pott 2016-10-11 13:04:42 +01:00
parent 24f816a11c
commit bcee34dbcc
2 changed files with 31 additions and 3 deletions

View File

@ -156,9 +156,12 @@ class BookNavigationBlock extends BlockBase implements ContainerFactoryPluginInt
}
}
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) {

View File

@ -752,4 +752,29 @@ class BookTest extends WebTestBase {
$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.');
}
}