You are here

class AdministrativeArea in Address 8

Filter by administrative area.

@todo: Rebuild the exposed filter element via AJAX when the country changes.

Plugin annotation

@ViewsFilter("administrative_area");

Hierarchy

Expanded class hierarchy of AdministrativeArea

See also

https://www.drupal.org/node/2840717

File

src/Plugin/views/filter/AdministrativeArea.php, line 24

Namespace

Drupal\address\Plugin\views\filter
View source
class AdministrativeArea extends CountryAwareInOperatorBase {

  /**
   * The address format repository.
   *
   * @var \CommerceGuys\Addressing\AddressFormat\AddressFormatRepositoryInterface
   */
  protected $addressFormatRepository;

  /**
   * The subdivision repository.
   *
   * @var \CommerceGuys\Addressing\Subdivision\SubdivisionRepositoryInterface
   */
  protected $subdivisionRepository;

  /**
   * If we're in the middle of building a form, its current state.
   *
   * @var \Drupal\Core\Form\FormStateInterface
   */
  protected $formState;

  /**
   * The currently selected country (if any).
   *
   * @var string
   */
  protected $currentCountryCode;

  /**
   * Constructs a new AdministrativeArea object.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \CommerceGuys\Addressing\Country\CountryRepositoryInterface $country_repository
   *   The country repository.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
   *   The entity field manager.
   * @param \CommerceGuys\Addressing\AddressFormat\AddressFormatRepositoryInterface $address_format_repository
   *   The address format repository.
   * @param \CommerceGuys\Addressing\Subdivision\SubdivisionRepositoryInterface $subdivision_repository
   *   The subdivision repository.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, CountryRepositoryInterface $country_repository, EntityTypeManagerInterface $entity_type_manager, EntityFieldManagerInterface $entity_field_manager, AddressFormatRepositoryInterface $address_format_repository, SubdivisionRepositoryInterface $subdivision_repository) {
    parent::__construct($configuration, $plugin_id, $plugin_definition, $country_repository, $entity_type_manager, $entity_field_manager);
    $this->addressFormatRepository = $address_format_repository;
    $this->subdivisionRepository = $subdivision_repository;
    $this->formState = NULL;
    $this->currentCountryCode = '';
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('address.country_repository'), $container
      ->get('entity_type.manager'), $container
      ->get('entity_field.manager'), $container
      ->get('address.address_format_repository'), $container
      ->get('address.subdivision_repository'));
  }

  /**
   * {@inheritdoc}
   */
  protected function defineOptions() {
    $options = parent::defineOptions();
    $options['country'] = [
      'contains' => [
        'country_source' => [
          'default' => '',
        ],
        'country_argument_id' => [
          'default' => '',
        ],
        'country_filter_id' => [
          'default' => '',
        ],
        'country_static_code' => [
          'default' => '',
        ],
      ],
    ];
    $options['expose']['contains']['label_type']['default'] = 'static';
    return $options;
  }

  /**
   * {@inheritdoc}
   */
  protected function canBuildGroup() {

    // To be able to define a group, you have to be able to select values
    // while configuring the filter. But this filter doesn't let you select
    // values until a country is selected, so the group filter functionality
    // is impossible.
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    $this->formState = $form_state;
    $form['country'] = [
      '#type' => 'container',
      '#weight' => -300,
    ];
    $form['country']['country_source'] = [
      '#type' => 'radios',
      '#title' => $this
        ->t('Country source'),
      '#options' => [
        'static' => $this
          ->t('A predefined country code'),
        'argument' => $this
          ->t('The value of a contextual filter'),
        'filter' => $this
          ->t('The value of an exposed filter'),
      ],
      '#default_value' => $this->options['country']['country_source'],
      '#ajax' => [
        'callback' => [
          get_class($this),
          'ajaxRefreshCountry',
        ],
        'wrapper' => 'admin-area-value-options-ajax-wrapper',
      ],
    ];
    $argument_options = [];

    // Find all the contextual filters on the display to use as options.
    foreach ($this->view->display_handler
      ->getHandlers('argument') as $name => $argument) {

      // @todo Limit this to arguments pointing to a country code field.
      // @see https://www.drupal.org/project/address/issues/3088084
      $argument_options[$name] = $argument
        ->adminLabel();
    }
    if (!empty($argument_options)) {
      $form['country']['country_argument_id'] = [
        '#type' => 'select',
        '#title' => $this
          ->t('Country contextual filter'),
        '#options' => $argument_options,
        '#default_value' => $this->options['country']['country_argument_id'],
      ];
    }
    else {

      // #states doesn't work on markup elements, so use a container.
      $form['country']['country_argument_id'] = [
        '#type' => 'container',
      ];
      $form['country']['country_argument_id']['error'] = [
        '#type' => 'markup',
        '#markup' => $this
          ->t('You must add a contextual filter for the country code to use this filter for administrative areas.'),
      ];
    }
    $form['country']['country_argument_id']['#states'] = [
      'visible' => [
        ':input[name="options[country][country_source]"]' => [
          'value' => 'argument',
        ],
      ],
    ];
    $filter_options = [];

    // Find all country filters from address.module for the valid choices.
    foreach ($this->view->display_handler
      ->getHandlers('filter') as $name => $filter) {
      $definition = $filter->pluginDefinition;

      // Support both 'country' (current) and 'country_code' (deprecated).
      if ($definition['provider'] === 'address' && ($definition['id'] === 'country' || $definition['id'] === 'country_code')) {
        $filter_options[$name] = $filter
          ->adminLabel();
      }
    }
    if (!empty($filter_options)) {
      $form['country']['country_filter_id'] = [
        '#type' => 'select',
        '#title' => $this
          ->t('Exposed country filter to determine values'),
        '#options' => $filter_options,
        '#default_value' => $this->options['country']['country_filter_id'],
      ];
    }
    else {

      // #states doesn't work on markup elements, so we to use a container.
      $form['country']['country_filter_id'] = [
        '#type' => 'container',
      ];
      $form['country']['country_filter_id']['error'] = [
        '#type' => 'markup',
        '#markup' => $this
          ->t('You must add a filter for the country code to use this filter for administrative areas.'),
      ];
    }
    $form['country']['country_filter_id']['#states'] = [
      'visible' => [
        ':input[name="options[country][country_source]"]' => [
          'value' => 'filter',
        ],
      ],
    ];
    $countries = $this
      ->getAdministrativeAreaCountries();
    $form['country']['country_static_code'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Predefined country for administrative areas'),
      '#options' => $countries,
      '#empty_value' => '',
      '#default_value' => $this->options['country']['country_static_code'],
      '#ajax' => [
        'callback' => [
          get_class($this),
          'ajaxRefreshCountry',
        ],
        'wrapper' => 'admin-area-value-options-ajax-wrapper',
      ],
      '#states' => [
        'visible' => [
          ':input[name="options[country][country_source]"]' => [
            'value' => 'static',
          ],
        ],
      ],
    ];

    // @todo This should appear directly above $form['expose']['label'].
    $form['expose']['label_type'] = [
      '#type' => 'radios',
      '#title' => $this
        ->t('Label type'),
      '#options' => [
        'static' => $this
          ->t('Static'),
        'dynamic' => $this
          ->t('Dynamic (an appropriate label will be set based on the active country)'),
      ],
      '#default_value' => $this->options['expose']['label_type'],
      '#states' => [
        'visible' => [
          ':input[name="options[expose_button][checkbox][checkbox]"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
    ];
    parent::buildOptionsForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function validateOptionsForm(&$form, FormStateInterface $form_state) {
    if (empty($form_state)) {
      return;
    }
    $is_exposed = !empty($this->options['exposed']);
    $country_source = $form_state
      ->getValue([
      'options',
      'country',
      'country_source',
    ]);
    switch ($country_source) {
      case 'argument':
        $country_argument = $form_state
          ->getValue([
          'options',
          'country',
          'country_argument_id',
        ]);
        if (empty($country_argument)) {
          $error = $this
            ->t("The country contextual filter must be defined for this filter to work using 'contextual filter' for the 'Country source'.");
          $form_state
            ->setError($form['country']['country_source'], $error);
        }
        if (empty($is_exposed)) {
          $error = $this
            ->t('This filter must be exposed to use a contextual filter to specify the country.');
          $form_state
            ->setError($form['country']['country_source'], $error);
        }
        break;
      case 'filter':
        $country_filter = $form_state
          ->getValue([
          'options',
          'country',
          'country_filter_id',
        ]);
        if (empty($country_filter)) {
          $error = $this
            ->t("The country filter must be defined for this filter to work using 'exposed filter' for the 'Country source'.");
          $form_state
            ->setError($form['country']['country_source'], $error);
        }
        if (empty($is_exposed)) {
          $error = $this
            ->t('This filter must be exposed to use a filter to specify the country.');
          $form_state
            ->setError($form['country']['country_source'], $error);
        }
        break;
      case 'static':
        $country_code = $form_state
          ->getValue([
          'options',
          'country',
          'country_static_code',
        ]);
        if (empty($country_code)) {
          $error = $this
            ->t('The predefined country must be set for this filter to work.');
          $form_state
            ->setError($form['country']['country_static_code'], $error);
        }
        break;
      default:
        $error = $this
          ->t('The  source for the country must be defined for this filter to work.');
        $form_state
          ->setError($form['country']['country_source'], $error);
        break;
    }
    parent::validateOptionsForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function buildExposeForm(&$form, FormStateInterface $form_state) {
    parent::buildExposeForm($form, $form_state);

    // Only show the label element if we're configured for a static label.
    $form['expose']['label']['#states'] = [
      'visible' => [
        ':input[name="options[expose][label_type]"]' => [
          'value' => 'static',
        ],
      ],
    ];

    // Only show the reduce option if we have a static country. If we're
    // getting values from a filter or argument, there are no fixed values to
    // reduce to.
    $form['expose']['reduce']['#states'] = [
      'visible' => [
        ':input[name="options[country][country_source]"]' => [
          'value' => 'static',
        ],
      ],
    ];

    // Repair the wrapper container on $form['value'] clobbered by
    // FilterPluginBase::buildExposeForm().
    $form['value']['#prefix'] = '<div id="admin-area-value-options-ajax-wrapper" class="views-group-box views-right-60">';
    $form['value']['#suffix'] = '</div>';
    return $form;
  }

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

    // If the country source is anything other than static, we have to
    // ignore/disable the "reduce" option since it doesn't make any sense and
    // will cause problems if the stale configuration is saved.
    // Similarly, we clear out any selections for specific administrative areas.
    $country_source = $form_state
      ->getValue([
      'options',
      'country',
      'country_source',
    ]);
    if ($country_source != 'static') {
      $form_state
        ->setValue([
        'options',
        'expose',
        'reduce',
      ], FALSE);
      $form_state
        ->setValue([
        'options',
        'value',
      ], []);
    }
    parent::submitExposeForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  protected function showValueForm(&$form, FormStateInterface $form_state) {
    $this
      ->valueForm($form, $form_state);
    $form['value']['#prefix'] = '<div id="admin-area-value-options-ajax-wrapper">';
    $form['value']['#suffix'] = '</div>';
  }

  /**
   * {@inheritdoc}
   */
  public function valueForm(&$form, FormStateInterface $form_state) {
    $this->valueOptions = [];
    $this->formState = $form_state;
    $country_source = $this
      ->getCountrySource();
    if ($country_source == 'static' || $form_state
      ->get('exposed')) {
      $this
        ->getCurrentCountry();
      parent::valueForm($form, $form_state);
      $form['value']['#after_build'][] = [
        get_class($this),
        'clearValues',
      ];
    }
    else {
      $form['value'] = [
        '#type' => 'container',
        '#attributes' => [
          'id' => 'admin-area-value-options-ajax-wrapper',
        ],
      ];
      $form['value']['message'] = [
        '#type' => 'markup',
        '#markup' => $this
          ->t("You can only select options here if you use a predefined country for the 'Country source'."),
      ];
    }
  }

  /**
   * {@inheritdoc}
   */
  protected function valueSubmit($form, FormStateInterface $form_state) {
    $this->formState = $form_state;
    $country_source = $this
      ->getCountrySource();
    if ($country_source == 'static') {

      // Only save the values if we've got a static country code.
      parent::valueSubmit($form, $form_state);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function exposedInfo() {
    $info = parent::exposedInfo();
    if ($this->options['expose']['label_type'] == 'dynamic') {
      $current_country = $this
        ->getCurrentCountry();
      if (!empty($current_country)) {
        $address_format = $this->addressFormatRepository
          ->get($current_country);
        $labels = LabelHelper::getFieldLabels($address_format);
        if (!empty($labels['administrativeArea'])) {
          $info['label'] = $labels['administrativeArea'];
        }
      }
    }
    return $info;
  }

  /**
   * Gets the current source for the country code.
   *
   * If defined in the current values of the configuration form, use
   * that. Otherwise, fall back to the filter configuration.
   *
   * @return string
   *   The country source.
   */
  protected function getCountrySource() {

    // If we're rebuilding via AJAX, we want the country source from the form
    // state, not the configuration.
    $country_source = '';
    if (!empty($this->formState)) {

      // First, see if there's a legitimate value in the form state.
      $form_value_country_source = $this->formState
        ->getValue([
        'options',
        'country',
        'country_source',
      ]);
      if (!empty($form_value_country_source)) {
        $country_source = $form_value_country_source;
      }
      else {

        // At various stages of building/validating the form, we might have
        // user input but not yet have the value saved into the form
        // state. So, if we have a form state but still don't have a value,
        // see if it is defined in the user input.
        $input = $this->formState
          ->getUserInput();
        if (!empty($input['options']['country']['country_source'])) {
          $country_source = $input['options']['country']['country_source'];
        }
      }
    }

    // If we don't have a source via the form state, use our configuration.
    if (empty($country_source)) {
      $country_source = $this->options['country']['country_source'];
    }
    return $country_source;
  }

  /**
   * Gets the currently active country code.
   *
   * The country source determines where to look for the country code. It can
   * either be predefined, in which case we simply return the current value of
   * the static country code (via form values or configuration). We can look
   * for the country via a Views argument, in which case we determine the
   * current value of the argument. Or we can get the country from another
   * exposed filter, in which case we look in the form values to find the
   * current country code from the other filter.
   *
   * @return string
   *   The 2-letter country code.
   */
  protected function getCurrentCountry() {
    $this->currentCountryCode = '';
    switch ($this
      ->getCountrySource()) {
      case 'argument':
        $country_argument = $this->view->display_handler
          ->getHandler('argument', $this->options['country']['country_argument_id']);
        if (!empty($country_argument)) {
          $this->currentCountryCode = $country_argument
            ->getValue();
        }
        break;
      case 'filter':
        $country_filter = $this->view->display_handler
          ->getHandler('filter', $this->options['country']['country_filter_id']);
        if (!empty($country_filter) && !empty($this->formState)) {
          $input = $this->formState
            ->getUserInput();
          $country_filter_identifier = $country_filter->options['expose']['identifier'];
          if (!empty($input[$country_filter_identifier])) {
            if (is_array($input[$country_filter_identifier])) {

              // @todo Maybe the config validation should prevent multi-valued
              // country filters. For now, we only provide administrative area
              // options if a single country is selected.
              if (count($input[$country_filter_identifier]) == 1) {
                $this->currentCountryCode = array_shift($input[$country_filter_identifier]);
              }
            }
            else {
              $this->currentCountryCode = $input[$country_filter_identifier];
            }
          }
        }
        break;
      case 'static':
        if (!empty($this->formState)) {

          // During filter configuration validation, we still need to know the
          // current country code, but the values won't yet be saved into the
          // ones accessible via FormStateInterface::getValue(). So, directly
          // inspect the user input instead of the official form values.
          $input = $this->formState
            ->getUserInput();
          if (!empty($input['options']['country']['country_static_code'])) {
            $form_input_country_code = $input['options']['country']['country_static_code'];
          }
        }
        $this->currentCountryCode = !empty($form_input_country_code) ? $form_input_country_code : $this->options['country']['country_static_code'];
        break;
    }

    // Since the country code can come from all sorts of non-validated user
    // input (e.g. GET parameters) and since it might be 'All', ensure we've
    // got a valid country code before we proceed. Other code in this
    // filter (and especially upstream in the AddressFormatRepository and
    // others) will explode if passed an invalid country code.
    if (!empty($this->currentCountryCode)) {
      $all_countries = $this->countryRepository
        ->getList();
      if (empty($all_countries[$this->currentCountryCode])) {
        $this->currentCountryCode = '';
      }
    }
    return $this->currentCountryCode;
  }

  /**
   * {@inheritdoc}
   */
  public function getValueOptions() {
    $this->valueOptions = [];
    if ($country_code = $this
      ->getCurrentCountry()) {
      $parents[] = $country_code;
      $locale = \Drupal::languageManager()
        ->getConfigOverrideLanguage()
        ->getId();
      $subdivisions = $this->subdivisionRepository
        ->getList($parents, $locale);
      $this->valueOptions = $subdivisions;
    }
    return $this->valueOptions;
  }

  /**
   * {@inheritdoc}
   */
  public function buildExposedForm(&$form, FormStateInterface $form_state) {
    parent::buildExposedForm($form, $form_state);

    // Hide the form element if we have no options to select.
    // (e.g. the country isn't set or it doesn't use administrative areas).
    if (empty($this->valueOptions)) {
      $identifier = $this->options['expose']['identifier'];
      $form[$identifier]['#access'] = FALSE;
    }
  }

  /**
   * {@inheritdoc}
   */
  public function adminSummary() {
    switch ($this->options['country']['country_source']) {
      case 'argument':
        return $this
          ->t('exposed: country set via contextual filter');
      case 'filter':
        return $this
          ->t('exposed: country set via exposed filter');
      case 'static':
        if (!empty($this->options['exposed'])) {
          return $this
            ->t('exposed: fixed country: @country', [
            '@country' => $this->options['country']['country_static_code'],
          ]);
        }
        return $this
          ->t('fixed country: @country', [
          '@country' => $this->options['country']['country_static_code'],
        ]);
    }
    return $this
      ->t('broken configuration');
  }

  /**
   * Gets a list of countries that have administrative areas.
   *
   * @param array $available_countries
   *   The available countries to filter by.
   *   Defaults to the available countries for this filter.
   *
   * @return array
   *   An array of country names, keyed by country code.
   */
  public function getAdministrativeAreaCountries(array $available_countries = NULL) {
    if (!isset($available_countries)) {
      $available_countries = $this
        ->getAvailableCountries();
    }
    $countries = [];
    foreach ($available_countries as $country_code => $country_name) {
      $address_format = $this->addressFormatRepository
        ->get($country_code);
      $subdivision_depth = $address_format
        ->getSubdivisionDepth();
      if ($subdivision_depth > 0) {
        $countries[$country_code] = $country_name;
      }
    }
    return $countries;
  }

  /**
   * Ajax callback.
   */
  public static function ajaxRefreshCountry(array $form, FormStateInterface $form_state) {
    return $form['options']['value'];
  }

  /**
   * Clears the administrative area form values when the country changes.
   *
   * Implemented as an #after_build callback because #after_build runs before
   * validation, allowing the values to be cleared early enough to prevent the
   * "Illegal choice" error.
   */
  public static function clearValues(array $element, FormStateInterface $form_state) {
    $triggering_element = $form_state
      ->getTriggeringElement();
    if (!$triggering_element) {
      return $element;
    }
    $triggering_element_name = end($triggering_element['#parents']);
    if ($triggering_element_name == 'country_static_code' || $triggering_element_name == 'country_source') {
      foreach ($element['#options'] as $key => $option) {
        $element[$key]['#value'] = 0;
      }
      $element['#value'] = [];
      $input =& $form_state
        ->getUserInput();
      $input['options']['value'] = [];
    }
    return $element;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AdministrativeArea::$addressFormatRepository protected property The address format repository.
AdministrativeArea::$currentCountryCode protected property The currently selected country (if any).
AdministrativeArea::$formState protected property If we're in the middle of building a form, its current state.
AdministrativeArea::$subdivisionRepository protected property The subdivision repository.
AdministrativeArea::adminSummary public function Display the filter on the administrative summary Overrides InOperator::adminSummary
AdministrativeArea::ajaxRefreshCountry public static function Ajax callback.
AdministrativeArea::buildExposedForm public function Render our chunk of the exposed filter form when selecting Overrides FilterPluginBase::buildExposedForm
AdministrativeArea::buildExposeForm public function Options form subform for exposed filter options. Overrides InOperator::buildExposeForm
AdministrativeArea::buildOptionsForm public function Provide the basic form which calls through to subforms. If overridden, it is best to call through to the parent, or to at least make sure all of the functions in this form are called. Overrides FilterPluginBase::buildOptionsForm
AdministrativeArea::canBuildGroup protected function Determine if a filter can be converted into a group. Only exposed filters with operators available can be converted into groups. Overrides FilterPluginBase::canBuildGroup
AdministrativeArea::clearValues public static function Clears the administrative area form values when the country changes.
AdministrativeArea::create public static function Creates an instance of the plugin. Overrides CountryAwareInOperatorBase::create
AdministrativeArea::defineOptions protected function Information about options for all kinds of purposes will be held here. Overrides InOperator::defineOptions
AdministrativeArea::exposedInfo public function Tell the renderer about our exposed form. This only needs to be overridden for particularly complex forms. And maybe not even then. Overrides FilterPluginBase::exposedInfo
AdministrativeArea::getAdministrativeAreaCountries public function Gets a list of countries that have administrative areas.
AdministrativeArea::getCountrySource protected function Gets the current source for the country code.
AdministrativeArea::getCurrentCountry protected function Gets the currently active country code.
AdministrativeArea::getValueOptions public function Child classes should be used to override this function and set the 'value options', unless 'options callback' is defined as a valid function or static public method to generate these values. Overrides InOperator::getValueOptions
AdministrativeArea::showValueForm protected function Shortcut to display the value form. Overrides FilterPluginBase::showValueForm
AdministrativeArea::submitExposeForm public function Perform any necessary changes to the form exposes prior to storage. There is no need for this function to actually store the data. Overrides HandlerBase::submitExposeForm
AdministrativeArea::validateOptionsForm public function Simple validate handler Overrides FilterPluginBase::validateOptionsForm
AdministrativeArea::valueForm public function Options form subform for setting options. Overrides InOperator::valueForm
AdministrativeArea::valueSubmit protected function Perform any necessary changes to the form values prior to storage. There is no need for this function to actually store the data. Overrides InOperator::valueSubmit
AdministrativeArea::__construct public function Constructs a new AdministrativeArea object. Overrides CountryAwareInOperatorBase::__construct
CountryAwareInOperatorBase::$countryRepository protected property The country repository.
CountryAwareInOperatorBase::$entityFieldManager protected property The entity field manager.
CountryAwareInOperatorBase::$entityTypeManager protected property The entity type manager.
CountryAwareInOperatorBase::getAvailableCountries protected function Gets the list of available countries for the current entity field.
CountryAwareInOperatorBase::getBundles protected function Gets the bundles for the current entity field.
CountryAwareInOperatorBase::getFieldName protected function Gets the name of the entity field on which this filter operates.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FilterPluginBase::$alwaysMultiple protected property Disable the possibility to force a single value. 6
FilterPluginBase::$always_required public property Disable the possibility to allow a exposed input to be optional.
FilterPluginBase::$group_info public property Contains the information of the selected item in a grouped filter.
FilterPluginBase::$no_operator public property Disable the possibility to use operators. 1
FilterPluginBase::$operator public property Contains the operator which is used on the query.
FilterPluginBase::$value public property Contains the actual value of the field,either configured in the views ui or entered in the exposed filters.
FilterPluginBase::addGroupForm public function Add a new group to the exposed filter groups.
FilterPluginBase::arrayFilterZero protected static function Filter by no empty values, though allow the use of (string) "0".
FilterPluginBase::buildExposedFiltersGroupForm protected function Build the form to let users create the group of exposed filters. This form is displayed when users click on button 'Build group'
FilterPluginBase::buildGroupForm public function Displays the Build Group form.
FilterPluginBase::buildGroupOptions protected function Provide default options for exposed filters.
FilterPluginBase::buildGroupSubmit protected function Save new group items, re-enumerates and remove groups marked to delete.
FilterPluginBase::buildGroupValidate protected function Validate the build group options form.
FilterPluginBase::canExpose public function Determine if a filter can be exposed. Overrides HandlerBase::canExpose 5
FilterPluginBase::canGroup public function Can this filter be used in OR groups? 1
FilterPluginBase::convertExposedInput public function Transform the input from a grouped filter into a standard filter.
FilterPluginBase::exposedTranslate protected function Make some translations to a form item to make it more suitable to exposing.
FilterPluginBase::getCacheContexts public function The cache contexts associated with this object. Overrides CacheableDependencyInterface::getCacheContexts 7
FilterPluginBase::getCacheMaxAge public function The maximum age for which this object may be cached. Overrides CacheableDependencyInterface::getCacheMaxAge
FilterPluginBase::getCacheTags public function The cache tags associated with this object. Overrides CacheableDependencyInterface::getCacheTags 1
FilterPluginBase::groupForm public function Build a form containing a group of operator | values to apply as a single filter.
FilterPluginBase::groupMultipleExposedInput public function Returns the options available for a grouped filter that users checkboxes as widget, and therefore has to be applied several times, one per item selected.
FilterPluginBase::hasValidGroupedValue protected function Determines if the given grouped filter entry has a valid value. 1
FilterPluginBase::isAGroup public function Returns TRUE if the exposed filter works like a grouped filter. Overrides HandlerBase::isAGroup
FilterPluginBase::multipleExposedInput public function Returns TRUE if users can select multiple groups items of a grouped exposed filter. Overrides HandlerBase::multipleExposedInput
FilterPluginBase::operatorForm protected function Options form subform for setting the operator. 6
FilterPluginBase::operatorSubmit public function Perform any necessary changes to the form values prior to storage. There is no need for this function to actually store the data.
FilterPluginBase::operatorValidate protected function Validate the operator form.
FilterPluginBase::prepareFilterSelectOptions protected function Sanitizes the HTML select element's options.
FilterPluginBase::showBuildGroupButton protected function Shortcut to display the build_group/hide button.
FilterPluginBase::showBuildGroupForm public function Shortcut to display the exposed options form.
FilterPluginBase::showExposeButton public function Shortcut to display the expose/hide button. Overrides HandlerBase::showExposeButton
FilterPluginBase::showOperatorForm public function Shortcut to display the operator form.
FilterPluginBase::storeExposedInput public function If set to remember exposed input in the session, store it there. Overrides HandlerBase::storeExposedInput
FilterPluginBase::storeGroupInput public function If set to remember exposed input in the session, store it there. This function is similar to storeExposedInput but modified to work properly when the filter is a group.
FilterPluginBase::submitOptionsForm public function Simple submit handler Overrides PluginBase::submitOptionsForm
FilterPluginBase::trustedCallbacks public static function Lists the trusted callbacks provided by the implementing class. Overrides PluginBase::trustedCallbacks
FilterPluginBase::validateExposeForm public function Validate the options form. Overrides HandlerBase::validateExposeForm
FilterPluginBase::validateIdentifier protected function Validates a filter identifier.
FilterPluginBase::valueValidate protected function Validate the options form. 3
HandlerBase::$field public property With field you can override the realField if the real field is not set.
HandlerBase::$moduleHandler protected property The module handler. 3
HandlerBase::$query public property Where the $query object will reside: 7
HandlerBase::$realField public property The actual field in the database table, maybe different on other kind of query plugins/special handlers.
HandlerBase::$relationship public property The relationship used for this field.
HandlerBase::$table public property The table this handler is attached to.
HandlerBase::$tableAlias public property The alias of the table of this handler which is used in the query.
HandlerBase::$viewsData protected property The views data service.
HandlerBase::access public function Check whether given user has access to this handler. Overrides ViewsHandlerInterface::access 4
HandlerBase::adminLabel public function Return a string representing this handler's name in the UI. Overrides ViewsHandlerInterface::adminLabel 4
HandlerBase::breakString public static function Breaks x,y,z and x+y+z into an array. Overrides ViewsHandlerInterface::breakString
HandlerBase::broken public function Determines if the handler is considered 'broken', meaning it's a placeholder used when a handler can't be found. Overrides ViewsHandlerInterface::broken
HandlerBase::buildExtraOptionsForm public function Provide a form for setting options. 1
HandlerBase::buildGroupByForm public function Provide a form for aggregation settings. 1
HandlerBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides PluginBase::calculateDependencies 10
HandlerBase::caseTransform protected function Transform a string by a certain method.
HandlerBase::defineExtraOptions public function Provide defaults for the handler.
HandlerBase::displayExposedForm public function Displays the Expose form.
HandlerBase::ensureMyTable public function Ensure the main table for this handler is in the query. This is used a lot. Overrides ViewsHandlerInterface::ensureMyTable 2
HandlerBase::getDateField public function Creates cross-database SQL dates. 2
HandlerBase::getDateFormat public function Creates cross-database SQL date formatting. 2
HandlerBase::getEntityType public function Determines the entity type used by this handler. Overrides ViewsHandlerInterface::getEntityType
HandlerBase::getField public function Shortcut to get a handler's raw field value. Overrides ViewsHandlerInterface::getField
HandlerBase::getJoin public function Get the join object that should be used for this handler. Overrides ViewsHandlerInterface::getJoin
HandlerBase::getModuleHandler protected function Gets the module handler.
HandlerBase::getTableJoin public static function Fetches a handler to join one table to a primary table from the data cache. Overrides ViewsHandlerInterface::getTableJoin
HandlerBase::getViewsData protected function Gets views data service.
HandlerBase::hasExtraOptions public function If a handler has 'extra options' it will get a little settings widget and another form called extra_options. 1
HandlerBase::isExposed public function Determine if this item is 'exposed', meaning it provides form elements to let users modify the view.
HandlerBase::placeholder protected function Provides a unique placeholders for handlers.
HandlerBase::postExecute public function Run after the view is executed, before the result is cached. Overrides ViewsHandlerInterface::postExecute
HandlerBase::preQuery public function Run before the view is built. Overrides ViewsHandlerInterface::preQuery 2
HandlerBase::sanitizeValue public function Sanitize the value for output. Overrides ViewsHandlerInterface::sanitizeValue
HandlerBase::setModuleHandler public function Sets the module handler.
HandlerBase::setRelationship public function Called just prior to query(), this lets a handler set up any relationship it needs. Overrides ViewsHandlerInterface::setRelationship
HandlerBase::setViewsData public function
HandlerBase::showExposeForm public function Shortcut to display the exposed options form. Overrides ViewsHandlerInterface::showExposeForm
HandlerBase::submitExposed public function Submit the exposed handler form
HandlerBase::submitExtraOptionsForm public function Perform any necessary changes to the form values prior to storage. There is no need for this function to actually store the data.
HandlerBase::submitFormCalculateOptions public function Calculates options stored on the handler 1
HandlerBase::submitGroupByForm public function Perform any necessary changes to the form values prior to storage. There is no need for this function to actually store the data. 1
HandlerBase::submitTemporaryForm public function A submit handler that is used for storing temporary items when using multi-step changes, such as ajax requests.
HandlerBase::usesGroupBy public function Provides the handler some groupby. 13
HandlerBase::validateExposed public function Validate the exposed handler form 4
HandlerBase::validateExtraOptionsForm public function Validate the options form.
InOperator::$valueFormType protected property 2
InOperator::$valueOptions protected property Stores all operations which are available on the form.
InOperator::$valueTitle protected property The filter title.
InOperator::acceptExposedInput public function Determines if the input from a filter should change the generated query. Overrides FilterPluginBase::acceptExposedInput 2
InOperator::defaultExposeOptions public function Provide default options for exposed filters. Overrides FilterPluginBase::defaultExposeOptions
InOperator::init public function Overrides \Drupal\views\Plugin\views\HandlerBase::init(). Overrides FilterPluginBase::init 2
InOperator::opEmpty protected function
InOperator::operatorOptions public function Build strings from the operators() for 'select' options Overrides FilterPluginBase::operatorOptions 1
InOperator::operators public function This kind of construct makes it relatively easy for a child class to add or remove functionality by overriding this function and adding/removing items from this array. 1
InOperator::operatorValues protected function
InOperator::opSimple protected function 1
InOperator::query public function Add this filter to the query. Overrides FilterPluginBase::query 6
InOperator::reduceValueOptions public function When using exposed filters, we may be required to reduce the set.
InOperator::validate public function Validate that the plugin is correct and can be saved. Overrides FilterPluginBase::validate
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$definition public property Plugins's definition
PluginBase::$displayHandler public property The display object this plugin is for.
PluginBase::$options public property Options for this plugin will be held here.
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::$renderer protected property Stores the render API renderer. 3
PluginBase::$usesOptions protected property Denotes whether the plugin has an additional options form. 8
PluginBase::$view public property The top object of a view. 1
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::destroy public function Clears a plugin. Overrides ViewsPluginInterface::destroy 2
PluginBase::doFilterByDefinedOptions protected function Do the work to filter out stored options depending on the defined options.
PluginBase::filterByDefinedOptions public function Filter out stored options depending on the defined options. Overrides ViewsPluginInterface::filterByDefinedOptions
PluginBase::getAvailableGlobalTokens public function Returns an array of available token replacements. Overrides ViewsPluginInterface::getAvailableGlobalTokens
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::getProvider public function Returns the plugin provider. Overrides ViewsPluginInterface::getProvider
PluginBase::getRenderer protected function Returns the render API renderer. 1
PluginBase::globalTokenForm public function Adds elements for available core tokens to a form. Overrides ViewsPluginInterface::globalTokenForm
PluginBase::globalTokenReplace public function Returns a string with any core tokens replaced. Overrides ViewsPluginInterface::globalTokenReplace
PluginBase::INCLUDE_ENTITY constant Include entity row languages when listing languages.
PluginBase::INCLUDE_NEGOTIATED constant Include negotiated languages when listing languages.
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginBase::listLanguages protected function Makes an array of languages, optionally including special languages.
PluginBase::pluginTitle public function Return the human readable name of the display. Overrides ViewsPluginInterface::pluginTitle
PluginBase::preRenderAddFieldsetMarkup public static function Moves form elements into fieldsets for presentation purposes. Overrides ViewsPluginInterface::preRenderAddFieldsetMarkup
PluginBase::preRenderFlattenData public static function Flattens the structure of form elements. Overrides ViewsPluginInterface::preRenderFlattenData
PluginBase::queryLanguageSubstitutions public static function Returns substitutions for Views queries for languages.
PluginBase::setOptionDefaults protected function Fills up the options of the plugin with defaults.
PluginBase::summaryTitle public function Returns the summary of the settings in the display. Overrides ViewsPluginInterface::summaryTitle 6
PluginBase::themeFunctions public function Provide a full list of possible theme templates used by this style. Overrides ViewsPluginInterface::themeFunctions 1
PluginBase::unpackOptions public function Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away. Overrides ViewsPluginInterface::unpackOptions
PluginBase::usesOptions public function Returns the usesOptions property. Overrides ViewsPluginInterface::usesOptions 8
PluginBase::viewsTokenReplace protected function Replaces Views' tokens in a given string. The resulting string will be sanitized with Xss::filterAdmin. 1
PluginBase::VIEWS_QUERY_LANGUAGE_SITE_DEFAULT constant Query string to indicate the site default language.
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.
TrustedCallbackInterface::THROW_EXCEPTION constant Untrusted callbacks throw exceptions.
TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION constant Untrusted callbacks trigger silenced E_USER_DEPRECATION errors.
TrustedCallbackInterface::TRIGGER_WARNING constant Untrusted callbacks trigger E_USER_WARNING errors.