diff --git a/core/modules/views/src/Plugin/Block/ViewsBlock.php b/core/modules/views/src/Plugin/Block/ViewsBlock.php index ad8d7c9148e5..43ff658f983d 100644 --- a/core/modules/views/src/Plugin/Block/ViewsBlock.php +++ b/core/modules/views/src/Plugin/Block/ViewsBlock.php @@ -27,6 +27,11 @@ class ViewsBlock extends ViewsBlockBase { // entry for the view output by passing FALSE, because we're going to cache // the whole block instead. if ($output = $this->view->buildRenderable($this->displayID, [], FALSE)) { + // Override the label to the dynamic title configured in the view. + if (empty($this->configuration['views_label']) && $this->view->getTitle()) { + $output['#title'] = ['#markup' => $this->view->getTitle(), '#allowed_tags' => Xss::getHtmlTagList()]; + } + // Before returning the block output, convert it to a renderable array // with contextual links. $this->addContextualLinks($output); @@ -36,11 +41,6 @@ class ViewsBlock extends ViewsBlockBase { // #pre_render callback has already been applied. $output = View::preRenderViewElement($output); - // Override the label to the dynamic title configured in the view. - if (empty($this->configuration['views_label']) && $this->view->getTitle()) { - $output['#title'] = ['#markup' => $this->view->getTitle(), '#allowed_tags' => Xss::getHtmlTagList()]; - } - // When view_build is empty, the actual render array output for this View // is going to be empty. In that case, return just #cache, so that the // render system knows the reasons (cache contexts & tags) why this Views diff --git a/core/modules/views/tests/src/Kernel/Plugin/ViewsBlockTest.php b/core/modules/views/tests/src/Kernel/Plugin/ViewsBlockTest.php index fc85050c16be..f30db33a2b5f 100644 --- a/core/modules/views/tests/src/Kernel/Plugin/ViewsBlockTest.php +++ b/core/modules/views/tests/src/Kernel/Plugin/ViewsBlockTest.php @@ -5,7 +5,6 @@ namespace Drupal\Tests\views\Kernel\Plugin; use Drupal\views\Plugin\Block\ViewsBlock; use Drupal\views\Tests\ViewTestData; use Drupal\Tests\views\Kernel\ViewsKernelTestBase; -use Drupal\views\Views; /** * Tests native behaviors of the block views plugin. @@ -52,68 +51,4 @@ class ViewsBlockTest extends ViewsKernelTestBase { $this->assertEqual($views_block->getMachineNameSuggestion(), 'views_block__test_view_block_block_1'); } - /** - * Tests that ViewsBlock::build() produces the right output with title tokens. - * - * @see \Drupal\views\Plugin\Block::build() - */ - public function testBuildWithTitleToken() { - $view = Views::getView('test_view_block'); - $view->setDisplay(); - - // Set the title to the 'name' field in the first row. - $view->display_handler->setOption('title', '{{ name }}'); - $view->save(); - - $plugin_definition = [ - 'provider' => 'views', - ]; - $plugin_id = 'views_block:test_view_block-block_1'; - $views_block = ViewsBlock::create($this->container, [], $plugin_id, $plugin_definition); - - $build = $views_block->build(); - $this->assertEquals('George', $build['#title']['#markup']); - } - - /** - * Tests ViewsBlock::build() with a title override. - * - * @see \Drupal\views\Plugin\Block::build() - */ - public function testBuildWithTitleOverride() { - $view = Views::getView('test_view_block'); - $view->setDisplay(); - - // Add a fixed argument that sets a title and save the view. - $view->displayHandlers->get('default')->overrideOption('arguments', array( - 'name' => array( - 'default_action' => 'default', - 'title_enable' => TRUE, - 'title' => 'Overridden title', - 'default_argument_type' => 'fixed', - 'default_argument_options' => [ - 'argument' => 'fixed' - ], - 'validate' => array( - 'type' => 'none', - 'fail' => 'not found', - ), - 'id' => 'name', - 'table' => 'views_test_data', - 'field' => 'name', - 'plugin_id' => 'string', - ) - )); - $view->save(); - - $plugin_definition = [ - 'provider' => 'views', - ]; - $plugin_id = 'views_block:test_view_block-block_1'; - $views_block = ViewsBlock::create($this->container, [], $plugin_id, $plugin_definition); - - $build = $views_block->build(); - $this->assertEquals('Overridden title', $build['#title']['#markup']); - } - }