3 namespace Drupal\views\Plugin\Derivative;
5 use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
6 use Drupal\Core\Entity\EntityStorageInterface;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
10 * Provides block plugin definitions for all Views exposed filters.
12 * @see \Drupal\views\Plugin\Block\ViewsExposedFilterBlock
14 class ViewsExposedFilterBlock implements ContainerDeriverInterface {
17 * List of derivative definitions.
21 protected $derivatives = [];
26 * @var \Drupal\Core\Entity\EntityStorageInterface
28 protected $viewStorage;
31 * The base plugin ID that the derivative is for.
35 protected $basePluginId;
38 * Constructs a ViewsExposedFilterBlock object.
40 * @param string $base_plugin_id
42 * @param \Drupal\Core\Entity\EntityStorageInterface $view_storage
43 * The entity storage to load views.
45 public function __construct($base_plugin_id, EntityStorageInterface $view_storage) {
46 $this->basePluginId = $base_plugin_id;
47 $this->viewStorage = $view_storage;
53 public static function create(ContainerInterface $container, $base_plugin_id) {
56 $container->get('entity.manager')->getStorage('view')
63 public function getDerivativeDefinition($derivative_id, $base_plugin_definition) {
64 if (!empty($this->derivatives) && !empty($this->derivatives[$derivative_id])) {
65 return $this->derivatives[$derivative_id];
67 $this->getDerivativeDefinitions($base_plugin_definition);
68 return $this->derivatives[$derivative_id];
74 public function getDerivativeDefinitions($base_plugin_definition) {
75 // Check all Views for displays with an exposed filter block.
76 foreach ($this->viewStorage->loadMultiple() as $view) {
77 // Do not return results for disabled views.
78 if (!$view->status()) {
81 $executable = $view->getExecutable();
82 $executable->initDisplay();
83 foreach ($executable->displayHandlers as $display) {
84 if (isset($display) && $display->getOption('exposed_block')) {
85 // Add a block definition for the block.
86 if ($display->usesExposedFormInBlock()) {
87 $delta = $view->id() . '-' . $display->display['id'];
88 $desc = t('Exposed form: @view-@display_id', ['@view' => $view->id(), '@display_id' => $display->display['id']]);
89 $this->derivatives[$delta] = [
90 'admin_label' => $desc,
91 'config_dependencies' => [
93 $view->getConfigDependencyName(),
97 $this->derivatives[$delta] += $base_plugin_definition;
102 return $this->derivatives;