class ViewsExposedFilterBlock

Same name in this branch
  1. 10 core/modules/views/src/Plugin/Block/ViewsExposedFilterBlock.php \Drupal\views\Plugin\Block\ViewsExposedFilterBlock
Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/Derivative/ViewsExposedFilterBlock.php \Drupal\views\Plugin\Derivative\ViewsExposedFilterBlock
  2. 9 core/modules/views/src/Plugin/Block/ViewsExposedFilterBlock.php \Drupal\views\Plugin\Block\ViewsExposedFilterBlock
  3. 8.9.x core/modules/views/src/Plugin/Derivative/ViewsExposedFilterBlock.php \Drupal\views\Plugin\Derivative\ViewsExposedFilterBlock
  4. 8.9.x core/modules/views/src/Plugin/Block/ViewsExposedFilterBlock.php \Drupal\views\Plugin\Block\ViewsExposedFilterBlock
  5. 11.x core/modules/views/src/Plugin/Derivative/ViewsExposedFilterBlock.php \Drupal\views\Plugin\Derivative\ViewsExposedFilterBlock
  6. 11.x core/modules/views/src/Plugin/Block/ViewsExposedFilterBlock.php \Drupal\views\Plugin\Block\ViewsExposedFilterBlock

Provides block plugin definitions for all Views exposed filters.

Hierarchy

Expanded class hierarchy of ViewsExposedFilterBlock

See also

\Drupal\views\Plugin\Block\ViewsExposedFilterBlock

1 file declares its use of ViewsExposedFilterBlock
ViewsExposedFilterBlock.php in core/modules/views/src/Plugin/Block/ViewsExposedFilterBlock.php

File

core/modules/views/src/Plugin/Derivative/ViewsExposedFilterBlock.php, line 15

Namespace

Drupal\views\Plugin\Derivative
View source
class ViewsExposedFilterBlock implements ContainerDeriverInterface {
    use StringTranslationTrait;
    
    /**
     * List of derivative definitions.
     *
     * @var array
     */
    protected $derivatives = [];
    
    /**
     * The view storage.
     *
     * @var \Drupal\Core\Entity\EntityStorageInterface
     */
    protected $viewStorage;
    
    /**
     * The base plugin ID that the derivative is for.
     *
     * @var string
     */
    protected $basePluginId;
    
    /**
     * Constructs a ViewsExposedFilterBlock object.
     *
     * @param string $base_plugin_id
     *   The base plugin ID.
     * @param \Drupal\Core\Entity\EntityStorageInterface $view_storage
     *   The entity storage to load views.
     */
    public function __construct($base_plugin_id, EntityStorageInterface $view_storage) {
        $this->basePluginId = $base_plugin_id;
        $this->viewStorage = $view_storage;
    }
    
    /**
     * {@inheritdoc}
     */
    public static function create(ContainerInterface $container, $base_plugin_id) {
        return new static($base_plugin_id, $container->get('entity_type.manager')
            ->getStorage('view'));
    }
    
    /**
     * {@inheritdoc}
     */
    public function getDerivativeDefinition($derivative_id, $base_plugin_definition) {
        if (!empty($this->derivatives) && !empty($this->derivatives[$derivative_id])) {
            return $this->derivatives[$derivative_id];
        }
        $this->getDerivativeDefinitions($base_plugin_definition);
        return $this->derivatives[$derivative_id];
    }
    
    /**
     * {@inheritdoc}
     */
    public function getDerivativeDefinitions($base_plugin_definition) {
        // Check all Views for displays with an exposed filter block.
        foreach ($this->viewStorage
            ->loadMultiple() as $view) {
            // Do not return results for disabled views.
            if (!$view->status()) {
                continue;
            }
            $executable = $view->getExecutable();
            $executable->initDisplay();
            foreach ($executable->displayHandlers as $display) {
                if (isset($display) && $display->getOption('exposed_block')) {
                    // Add a block definition for the block.
                    if ($display->usesExposedFormInBlock()) {
                        $delta = $view->id() . '-' . $display->display['id'];
                        $desc = $this->t('Exposed form: @view-@display_id', [
                            '@view' => $view->id(),
                            '@display_id' => $display->display['id'],
                        ]);
                        $this->derivatives[$delta] = [
                            'admin_label' => $desc,
                            'config_dependencies' => [
                                'config' => [
                                    $view->getConfigDependencyName(),
                                ],
                            ],
                        ];
                        $this->derivatives[$delta] += $base_plugin_definition;
                    }
                }
            }
        }
        return $this->derivatives;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
ViewsExposedFilterBlock::$basePluginId protected property The base plugin ID that the derivative is for.
ViewsExposedFilterBlock::$derivatives protected property List of derivative definitions.
ViewsExposedFilterBlock::$viewStorage protected property The view storage.
ViewsExposedFilterBlock::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
ViewsExposedFilterBlock::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
ViewsExposedFilterBlock::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverInterface::getDerivativeDefinitions
ViewsExposedFilterBlock::__construct public function Constructs a ViewsExposedFilterBlock object.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.