You are here

Hidden.php in Better Exposed Filters 8.4

Same filename and directory in other branches
  1. 8.5 src/Plugin/better_exposed_filters/filter/Hidden.php

File

src/Plugin/better_exposed_filters/filter/Hidden.php
View source
<?php

namespace Drupal\better_exposed_filters\Plugin\better_exposed_filters\filter;

use Drupal\Core\Form\FormStateInterface;

/**
 * Default widget implementation.
 *
 * @BetterExposedFiltersFilterWidget(
 *   id = "bef_hidden",
 *   label = @Translation("Hidden"),
 * )
 */
class Hidden extends FilterWidgetBase {

  /**
   * {@inheritdoc}
   */
  public function exposedFormAlter(array &$form, FormStateInterface $form_state) {
    $field_id = $this
      ->getExposedFilterFieldId();
    parent::exposedFormAlter($form, $form_state);
    if (empty($form[$field_id]['#multiple'])) {

      // Single entry filters can simply be changed to a different element
      // type.
      $form[$field_id]['#type'] = 'hidden';
    }
    else {

      // Hide the label.
      $form['#info']["filter-{$field_id}"]['label'] = '';
      $form[$field_id]['#title'] = '';

      // Use BEF's preprocess and template to output the hidden elements.
      $form[$field_id]['#theme'] = 'bef_hidden';
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function isApplicable($filter = NULL, array $filter_options = []) {
    $is_applicable = parent::isApplicable($filter, $filter_options);
    if ((is_a($filter, 'Drupal\\views\\Plugin\\views\\filter\\Date') || !empty($filter->date_handler)) && !$filter
      ->isAGroup()) {
      $is_applicable = TRUE;
    }
    return $is_applicable;
  }

}

Classes

Namesort descending Description
Hidden Default widget implementation.