You are here

protected function FilterHtml::prepareAttributeValues in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/filter/src/Plugin/Filter/FilterHtml.php \Drupal\filter\Plugin\Filter\FilterHtml::prepareAttributeValues()
  2. 10 core/modules/filter/src/Plugin/Filter/FilterHtml.php \Drupal\filter\Plugin\Filter\FilterHtml::prepareAttributeValues()

Helper function to prepare attribute values including wildcards.

Splits the values into two lists, one for values that must match exactly and the other for values that are wildcard prefixes.

Parameters

bool|array $attribute_values: TRUE, FALSE, or an array of allowed values.

Return value

bool|array

1 call to FilterHtml::prepareAttributeValues()
FilterHtml::filterAttributes in core/modules/filter/src/Plugin/Filter/FilterHtml.php
Provides filtering of tag attributes into accepted HTML.

File

core/modules/filter/src/Plugin/Filter/FilterHtml.php, line 224

Class

FilterHtml
Provides a filter to limit allowed HTML tags.

Namespace

Drupal\filter\Plugin\Filter

Code

protected function prepareAttributeValues($attribute_values) {
  if ($attribute_values === TRUE || $attribute_values === FALSE) {
    return $attribute_values;
  }
  $result = [
    'exact' => [],
    'prefix' => [],
  ];
  foreach ($attribute_values as $name => $allowed) {

    // A trailing * indicates wildcard, but it must have some prefix.
    if (substr($name, -1) === '*' && $name[0] !== '*') {
      $result['prefix'][str_replace('*', '', $name)] = $allowed;
    }
    else {
      $result['exact'][$name] = $allowed;
    }
  }
  krsort($result['prefix']);
  return $result;
}