function FilterHtml::findAllowedValue

Same name and namespace in other branches
  1. 9 core/modules/filter/src/Plugin/Filter/FilterHtml.php \Drupal\filter\Plugin\Filter\FilterHtml::findAllowedValue()
  2. 8.9.x core/modules/filter/src/Plugin/Filter/FilterHtml.php \Drupal\filter\Plugin\Filter\FilterHtml::findAllowedValue()
  3. 10 core/modules/filter/src/Plugin/Filter/FilterHtml.php \Drupal\filter\Plugin\Filter\FilterHtml::findAllowedValue()

Helper function to handle prefix matching.

Parameters

array $allowed: Array of allowed names and prefixes.

string $name: The name to find or match against a prefix.

Return value

bool|array

1 call to FilterHtml::findAllowedValue()
FilterHtml::filterElementAttributes in core/modules/filter/src/Plugin/Filter/FilterHtml.php
Filters attributes on an element according to a list of allowed values.

File

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

Class

FilterHtml
Provides a filter to limit allowed HTML tags.

Namespace

Drupal\filter\Plugin\Filter

Code

protected function findAllowedValue(array $allowed, $name) {
    if (isset($allowed['exact'][$name])) {
        return $allowed['exact'][$name];
    }
    // Handle prefix (wildcard) matches.
    foreach ($allowed['prefix'] as $prefix => $value) {
        if (str_starts_with($name, $prefix)) {
            return $value;
        }
    }
    return FALSE;
}

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