diff --git a/core/modules/block_content/src/Plugin/Block/BlockContentBlock.php b/core/modules/block_content/src/Plugin/Block/BlockContentBlock.php index 2afd040..8d55658 100644 --- a/core/modules/block_content/src/Plugin/Block/BlockContentBlock.php +++ b/core/modules/block_content/src/Plugin/Block/BlockContentBlock.php @@ -158,7 +158,11 @@ protected function blockAccess(AccountInterface $account) { */ public function build() { if ($block = $this->getEntity()) { - return $this->entityManager->getViewBuilder($block->getEntityTypeId())->view($block, $this->configuration['view_mode']); + if ($block->isPublished()) { + return $this->entityManager + ->getViewBuilder($block->getEntityTypeId()) + ->view($block, $this->configuration['view_mode']); + } } else { return array( diff --git a/core/modules/block_content/tests/src/Functional/UnpublishedBlockTest.php b/core/modules/block_content/tests/src/Functional/UnpublishedBlockTest.php index e69de29..f6e4c4d 100644 --- a/core/modules/block_content/tests/src/Functional/UnpublishedBlockTest.php +++ b/core/modules/block_content/tests/src/Functional/UnpublishedBlockTest.php @@ -0,0 +1,48 @@ + 'basic']); + $block_content->save(); + + $this->placeBlock('block_content:' . $block_content->uuid()); + + $this->drupalGet(''); + $page = $this->getSession()->getPage(); + $html = $page->getHtml(); + $this->assertTrue($page->has('css', '.block-block-content' . $block_content->uuid())); + + $block_content->setPublished(FALSE); + $block_content->save(); + + $this->drupalGet(''); + $page = $this->getSession()->getPage(); + $html = $page->getHtml(); + $this->assertFalse($page->has('css', '.block-block-content' . $block_content->uuid())); + } +}