You are here

protected function BetterExposedFilters::cleanOptions in Better Exposed Filters 8.3

Cleans up options being sent to radio button or checkbox renderers.

Parameters

array $options: The options array to clean.

Return value

array Cleaned options array.

1 call to BetterExposedFilters::cleanOptions()
BetterExposedFilters::exposedFormAlter in src/Plugin/views/exposed_form/BetterExposedFilters.php
@inheritdoc

File

src/Plugin/views/exposed_form/BetterExposedFilters.php, line 1436

Class

BetterExposedFilters
Exposed form plugin that provides a basic exposed form.

Namespace

Drupal\better_exposed_filters\Plugin\views\exposed_form

Code

protected function cleanOptions(array $options) {

  // Check the first element to see if we need to clean this array. If it is
  // a scalar, then just return the array as-is.
  if (is_scalar(reset($options))) {
    return $options;
  }
  $clean = [];
  foreach ($options as $index => $value) {

    // Some options, such as the "any" text, are really just plain
    // text so we keep those as they are. Others, like taxonomy terms
    // need to be converted to text.
    if (is_object($value) && !is_a($value, 'Drupal\\Core\\StringTranslation\\TranslatableMarkup')) {
      reset($value->option);
      $key = key($value->option);
      $val = current($value->option);
      $clean[$key] = $val;
    }
    else {
      $clean[$index] = $value;
    }
  }
  return $clean;
}