diff --git a/core/modules/views/src/Plugin/Block/ViewsExposedFilterBlock.php b/core/modules/views/src/Plugin/Block/ViewsExposedFilterBlock.php index 4b40a0d..73c5d79 100644 --- a/core/modules/views/src/Plugin/Block/ViewsExposedFilterBlock.php +++ b/core/modules/views/src/Plugin/Block/ViewsExposedFilterBlock.php @@ -3,6 +3,7 @@ namespace Drupal\views\Plugin\Block; use Drupal\Core\Cache\Cache; +use Drupal\Component\Utility\Xss; /** * Provides a 'Views Exposed Filter' block. @@ -47,6 +48,14 @@ public function build() { // contextual links. $this->addContextualLinks($output, 'exposed_filter'); + // Set the blocks title. + if (!empty($this->configuration['label_display']) && ($this->view->getTitle() || !empty($this->configuration['views_label']))) { + $output['#title'] = [ + '#markup' => empty($this->configuration['views_label']) ? $this->view->getTitle() : $this->configuration['views_label'], + '#allowed_tags' => Xss::getHtmlTagList() + ]; + } + return $output; } diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_exposed_block.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_exposed_block.yml index be96ab4..df70195 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_exposed_block.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_exposed_block.yml @@ -14,6 +14,7 @@ core: '8' display: default: display_options: + title: 'Test Exposed Block' access: type: none cache: diff --git a/core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php b/core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php index eaa5aaa..35a96a7 100644 --- a/core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php @@ -199,7 +199,31 @@ public function testExposedBlock() { $view = Views::getView('test_exposed_block'); $view->setDisplay('page_1'); $block = $this->drupalPlaceBlock('views_exposed_filter_block:test_exposed_block-page_1'); + + // Set to display the label on the exposed filter form block. + $block->getPlugin()->setConfigurationValue('label_display', TRUE); + $block->save(); + + // Test that the block label is found. + $this->drupalGet('test_exposed_block'); + $this->assertText($view->getTitle(), 'Block title found.'); + + // Set a custom label on the exposed filter form block. + $block->getPlugin()->setConfigurationValue('views_label', 'Custom title'); + $block->save(); + + // Test that the custom block label is found. + $this->drupalGet('test_exposed_block'); + $this->assertRaw('Custom titlealert("hacked!");', 'Custom block title found.'); + + // Set to hide the label on the exposed filter form block. + $block->getPlugin()->setConfigurationValue('label_display', FALSE); + $block->save(); + + // Test that the label is removed. $this->drupalGet('test_exposed_block'); + $this->assertNoRaw('Custom titlealert("hacked!");', 'Custom title was not displayed.'); + $this->assertNoText($view->getTitle(), 'Block title was not displayed.'); // Test there is an exposed form in a block. $xpath = $this->buildXPathQuery('//div[@id=:id]/form/@id', [':id' => Html::getUniqueId('block-' . $block->id())]);