function FilterHtml::prepareAttributeValues

Same name in other branches
  1. 9 core/modules/filter/src/Plugin/Filter/FilterHtml.php \Drupal\filter\Plugin\Filter\FilterHtml::prepareAttributeValues()
  2. 8.9.x core/modules/filter/src/Plugin/Filter/FilterHtml.php \Drupal\filter\Plugin\Filter\FilterHtml::prepareAttributeValues()
  3. 11.x 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 (str_ends_with($name, '*') && $name[0] !== '*') {
            $result['prefix'][str_replace('*', '', $name)] = $allowed;
        }
        else {
            $result['exact'][$name] = $allowed;
        }
    }
    krsort($result['prefix']);
    return $result;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.