Issue #2743183 by szato, nielsvandermolen: Fatal error in Book navigation block for unpublished parent book item
parent
24f816a11c
commit
bcee34dbcc
|
@ -156,9 +156,12 @@ class BookNavigationBlock extends BlockBase implements ContainerFactoryPluginInt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif ($current_bid) {
|
elseif ($current_bid) {
|
||||||
// Only display this block when the user is browsing a book.
|
// Only display this block when the user is browsing a book and do
|
||||||
$query = \Drupal::entityQuery('node');
|
// not show unpublished books.
|
||||||
$nid = $query->condition('nid', $node->book['bid'], '=')->execute();
|
$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.
|
// Only show the block if the user has view access for the top-level node.
|
||||||
if ($nid) {
|
if ($nid) {
|
||||||
|
|
|
@ -752,4 +752,29 @@ class BookTest extends WebTestBase {
|
||||||
$this->assertEqual($book_node->book['bid'], $this->book->id());
|
$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.');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue