You are here

class Links in Better Exposed Filters 8.4

Same name in this branch
  1. 8.4 src/Plugin/better_exposed_filters/filter/Links.php \Drupal\better_exposed_filters\Plugin\better_exposed_filters\filter\Links
  2. 8.4 src/Plugin/better_exposed_filters/sort/Links.php \Drupal\better_exposed_filters\Plugin\better_exposed_filters\sort\Links
  3. 8.4 src/Plugin/better_exposed_filters/pager/Links.php \Drupal\better_exposed_filters\Plugin\better_exposed_filters\pager\Links
Same name and namespace in other branches
  1. 8.5 src/Plugin/better_exposed_filters/filter/Links.php \Drupal\better_exposed_filters\Plugin\better_exposed_filters\filter\Links

Default widget implementation.

Plugin annotation


@BetterExposedFiltersFilterWidget(
  id = "bef_links",
  label = @Translation("Links"),
)

Hierarchy

Expanded class hierarchy of Links

4 string references to 'Links'
better_exposed_filters.filter.schema.yml in config/schema/better_exposed_filters.filter.schema.yml
config/schema/better_exposed_filters.filter.schema.yml
better_exposed_filters.pager.schema.yml in config/schema/better_exposed_filters.pager.schema.yml
config/schema/better_exposed_filters.pager.schema.yml
better_exposed_filters.sort.schema.yml in config/schema/better_exposed_filters.sort.schema.yml
config/schema/better_exposed_filters.sort.schema.yml
hook_better_exposed_filters_filter_widgets_alter in ./better_exposed_filters.api.php
Modify the array of BEF display options for an exposed filter.

File

src/Plugin/better_exposed_filters/filter/Links.php, line 16

Namespace

Drupal\better_exposed_filters\Plugin\better_exposed_filters\filter
View source
class Links extends FilterWidgetBase {

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return parent::defaultConfiguration() + [
      'select_all_none' => FALSE,
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {

    /** @var \Drupal\views\Plugin\views\filter\FilterPluginBase $filter */
    $filter = $this->handler;
    $form = parent::buildConfigurationForm($form, $form_state);
    $form['select_all_none'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Add select all/none links'),
      '#default_value' => !empty($this->configuration['select_all_none']),
      '#disabled' => !$filter->options['expose']['multiple'],
      '#description' => $this
        ->t('Add a "Select All/None" link when rendering the exposed filter using checkboxes. If this option is disabled, edit the filter and check the "Allow multiple selections".'),
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function exposedFormAlter(array &$form, FormStateInterface $form_state) {

    /** @var \Drupal\views\Plugin\views\filter\FilterPluginBase $filter */
    $filter = $this->handler;
    $field_id = $this
      ->getExposedFilterFieldId();
    parent::exposedFormAlter($form, $form_state);
    if (!empty($form[$field_id])) {

      // Clean up filters that pass objects as options instead of strings.
      if (!empty($form[$field_id]['#options'])) {
        $form[$field_id]['#options'] = BetterExposedFiltersHelper::flattenOptions($form[$field_id]['#options']);
      }

      // Support rendering hierarchical links (e.g. taxonomy terms).
      if (!empty($filter->options['hierarchy'])) {
        $form[$field_id]['#bef_nested'] = TRUE;
      }
      $form[$field_id]['#theme'] = 'bef_links';

      // Exposed form displayed as blocks can appear on pages other than
      // the view results appear on. This can cause problems with
      // select_as_links options as they will use the wrong path. We
      // provide a hint for theme functions to correct this.
      $form[$field_id]['#bef_path'] = $this
        ->getExposedFormActionUrl($form_state);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BetterExposedFiltersWidgetBase::$handler protected property The views plugin this configuration will affect when exposed.
BetterExposedFiltersWidgetBase::$view protected property The views executable object.
BetterExposedFiltersWidgetBase::addContext protected function Sets metadata on the form elements for easier processing.
BetterExposedFiltersWidgetBase::addElementToGroup protected function Moves an exposed form element into a field group.
BetterExposedFiltersWidgetBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
BetterExposedFiltersWidgetBase::getExposedFormActionUrl protected function Returns exposed form action URL object.
BetterExposedFiltersWidgetBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
BetterExposedFiltersWidgetBase::setView public function Sets the view object. Overrides BetterExposedFiltersWidgetInterface::setView
BetterExposedFiltersWidgetBase::setViewsHandler public function Sets the exposed view handler plugin. Overrides BetterExposedFiltersWidgetInterface::setViewsHandler
BetterExposedFiltersWidgetBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm
BetterExposedFiltersWidgetBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm 1
BetterExposedFiltersWidgetBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct
FilterWidgetBase::getExposedFilterFieldId protected function Helper function to get the unique identifier for the exposed filter.
FilterWidgetBase::getExposedFilterWidgetType protected function Helper function to get the widget type of the exposed filter.
FilterWidgetBase::isApplicable public static function Verify this plugin can be used on the form element. Overrides BetterExposedFiltersWidgetInterface::isApplicable 5
FilterWidgetBase::processSortedOptions public function Sorts the options for a given form element alphabetically.
Links::buildConfigurationForm public function Form constructor. Overrides FilterWidgetBase::buildConfigurationForm
Links::defaultConfiguration public function Gets default configuration for this plugin. Overrides FilterWidgetBase::defaultConfiguration
Links::exposedFormAlter public function Manipulate views exposed from element. Overrides FilterWidgetBase::exposedFormAlter
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
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.