4b40a0d31d6a8be44d42e1e92ddd81da1f6bc23c
[yaffs-website] / web / core / modules / views / src / Plugin / Block / ViewsExposedFilterBlock.php
1 <?php
2
3 namespace Drupal\views\Plugin\Block;
4
5 use Drupal\Core\Cache\Cache;
6
7 /**
8  * Provides a 'Views Exposed Filter' block.
9  *
10  * @Block(
11  *   id = "views_exposed_filter_block",
12  *   admin_label = @Translation("Views Exposed Filter Block"),
13  *   deriver = "Drupal\views\Plugin\Derivative\ViewsExposedFilterBlock"
14  * )
15  */
16 class ViewsExposedFilterBlock extends ViewsBlockBase {
17
18   /**
19    * {@inheritdoc}
20    */
21   public function getCacheContexts() {
22     $contexts = $this->view->display_handler->getCacheMetadata()->getCacheContexts();
23     return Cache::mergeContexts(parent::getCacheContexts(), $contexts);
24   }
25
26   /**
27    * {@inheritdoc}
28    *
29    * @return array
30    *   A renderable array representing the content of the block with additional
31    *   context of current view and display ID.
32    */
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)) {
40       $output += [
41         '#view' => $this->view,
42         '#display_id' => $this->displayID,
43       ];
44     }
45
46     // Before returning the block output, convert it to a renderable array with
47     // contextual links.
48     $this->addContextualLinks($output, 'exposed_filter');
49
50     return $output;
51   }
52
53 }