You are here

abstract class PagerWidgetBase in Better Exposed Filters 8.4

Same name and namespace in other branches
  1. 8.5 src/Plugin/better_exposed_filters/pager/PagerWidgetBase.php \Drupal\better_exposed_filters\Plugin\better_exposed_filters\pager\PagerWidgetBase

Base class for Better exposed pager widget plugins.

Hierarchy

Expanded class hierarchy of PagerWidgetBase

File

src/Plugin/better_exposed_filters/pager/PagerWidgetBase.php, line 13

Namespace

Drupal\better_exposed_filters\Plugin\better_exposed_filters\pager
View source
abstract class PagerWidgetBase extends BetterExposedFiltersWidgetBase implements BetterExposedFiltersWidgetInterface {
  use StringTranslationTrait;

  /**
   * List of available exposed sort form element keys.
   *
   * @var array
   */
  protected $pagerElements = [
    'items_per_page',
    'offset',
  ];

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

  /**
   * {@inheritdoc}
   */
  public static function isApplicable($handler = NULL, array $options = []) {
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form = [];
    $form['advanced']['is_secondary'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('This is a secondary option'),
      '#default_value' => !empty($this->configuration['advanced']['is_secondary']),
      '#states' => [
        'visible' => [
          ':input[name="exposed_form_options[bef][general][allow_secondary]"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
      '#description' => $this
        ->t('Places this element in the secondary options portion of the exposed form.'),
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function exposedFormAlter(array &$form, FormStateInterface $form_state) {
    $is_secondary = !empty($form['secondary']) && $this->configuration['advanced']['is_secondary'];
    foreach ($this->pagerElements as $element) {

      // Sanity check to make sure the element exists.
      if (empty($form[$element])) {
        continue;
      }
      if ($is_secondary) {
        $this
          ->addElementToGroup($form, $form_state, $element, 'secondary');
      }

      // Finally, add some metadata to the form element.
      $this
        ->addContext($form[$element]);
    }
  }

}

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
PagerWidgetBase::$pagerElements protected property List of available exposed sort form element keys.
PagerWidgetBase::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm
PagerWidgetBase::defaultConfiguration public function Gets default configuration for this plugin. Overrides BetterExposedFiltersWidgetBase::defaultConfiguration
PagerWidgetBase::exposedFormAlter public function Manipulate views exposed from element. Overrides BetterExposedFiltersWidgetInterface::exposedFormAlter 2
PagerWidgetBase::isApplicable public static function Verify this plugin can be used on the form element. Overrides BetterExposedFiltersWidgetInterface::isApplicable
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.