You are here

protected function FilterPluginBase::prepareFilterSelectOptions in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/views/filter/FilterPluginBase.php \Drupal\views\Plugin\views\filter\FilterPluginBase::prepareFilterSelectOptions()

Sanitizes the HTML select element's options.

The function is recursive to support optgroups.

1 call to FilterPluginBase::prepareFilterSelectOptions()
FilterPluginBase::exposedTranslate in core/modules/views/src/Plugin/views/filter/FilterPluginBase.php
Make some translations to a form item to make it more suitable to exposing.

File

core/modules/views/src/Plugin/views/filter/FilterPluginBase.php, line 1265

Class

FilterPluginBase
Base class for Views filters handler plugins.

Namespace

Drupal\views\Plugin\views\filter

Code

protected function prepareFilterSelectOptions(&$options) {
  foreach ($options as $value => $label) {

    // Recurse for optgroups.
    if (is_array($label)) {
      $this
        ->prepareFilterSelectOptions($options[$value]);
    }
    elseif (is_object($label) && isset($label->option)) {
      $this
        ->prepareFilterSelectOptions($options[$value]->option);
    }
    else {

      // Cast the label to a string since it can be an object.
      // @see \Drupal\Core\StringTranslation\TranslatableMarkup
      $options[$value] = strip_tags(Html::decodeEntities((string) $label));
    }
  }
}