3 namespace Drupal\views\Plugin\Block;
5 use Drupal\Core\Cache\Cache;
8 * Provides a 'Views Exposed Filter' block.
11 * id = "views_exposed_filter_block",
12 * admin_label = @Translation("Views Exposed Filter Block"),
13 * deriver = "Drupal\views\Plugin\Derivative\ViewsExposedFilterBlock"
16 class ViewsExposedFilterBlock extends ViewsBlockBase {
21 public function getCacheContexts() {
22 $contexts = $this->view->display_handler->getCacheMetadata()->getCacheContexts();
23 return Cache::mergeContexts(parent::getCacheContexts(), $contexts);
30 * A renderable array representing the content of the block with additional
31 * context of current view and display ID.
33 public function build() {
34 $output = $this->view->display_handler->viewExposedFormBlocks();
35 // Provide the context for block build and block view alter hooks.
36 // \Drupal\views\Plugin\Block\ViewsBlock::build() adds the same context in
37 // \Drupal\views\ViewExecutable::buildRenderable() using
38 // \Drupal\views\Plugin\views\display\DisplayPluginBase::buildRenderable().
39 if (is_array($output) && !empty($output)) {
41 '#view' => $this->view,
42 '#display_id' => $this->displayID,
46 // Before returning the block output, convert it to a renderable array with
48 $this->addContextualLinks($output, 'exposed_filter');