function HTMLRestrictions::resolveWildcards

Same name and namespace in other branches
  1. 9 core/modules/ckeditor5/src/HTMLRestrictions.php \Drupal\ckeditor5\HTMLRestrictions::resolveWildcards()
  2. 11.x core/modules/ckeditor5/src/HTMLRestrictions.php \Drupal\ckeditor5\HTMLRestrictions::resolveWildcards()

Resolves the wildcard tags (this consumes the wildcard tags).

Parameters

\Drupal\ckeditor5\HTMLRestrictions $r: A set of HTML restrictions.

Return value

\Drupal\ckeditor5\HTMLRestrictions The concrete interpretation of the given set of HTML restrictions. All wildcard tag restrictions are resolved into restrictions on concrete elements, if concrete elements are allowed that correspond to the wildcard tags.

See also

::getWildcardTags()

2 calls to HTMLRestrictions::resolveWildcards()
HTMLRestrictions::applyOperation in core/modules/ckeditor5/src/HTMLRestrictions.php
Applies an operation (difference/intersection/union) with wildcard support.
HTMLRestrictions::toFilterHtmlAllowedTagsString in core/modules/ckeditor5/src/HTMLRestrictions.php
Transforms into the Drupal HTML filter's "allowed_html" representation.

File

core/modules/ckeditor5/src/HTMLRestrictions.php, line 1136

Class

HTMLRestrictions
Represents a set of HTML restrictions.

Namespace

Drupal\ckeditor5

Code

private static function resolveWildcards(HTMLRestrictions $r) : HTMLRestrictions {
    // Start by resolving the wildcards in a naive, simple way: generate
    // tags, attributes and attribute values they support.
    $naively_resolved_wildcard_elements = [];
    foreach ($r->elements as $tag_name => $tag_config) {
        if (self::isWildcardTag($tag_name)) {
            $wildcard_tags = self::getWildcardTags($tag_name);
            // Do not resolve to all tags supported by the wildcard tag, but only
            // those which are explicitly supported. Because wildcard tags only
            // allow declaring support for additional attributes and attribute
            // values on already supported tags.
            foreach ($wildcard_tags as $wildcard_tag) {
                if (isset($r->elements[$wildcard_tag])) {
                    $naively_resolved_wildcard_elements[$wildcard_tag] = $tag_config;
                }
            }
        }
    }
    $naive_resolution = new self($naively_resolved_wildcard_elements);
    // Now merge the naive resolution's elements with the original elements, to
    // let ::merge() pick the most permissive one.
    // This is necessary because resolving wildcards may result in concrete tags
    // becoming either more permissive:
    // - if $r is `<p> <$text-container class="foo">`
    // - then $naive will be `<p class="foo">`
    // - merging them yields `<p class="foo"> <$text-container class="foo">`
    // - diffing the wildcard subsets yields just `<p class="foo">`
    // Or it could result in concrete tags being unaffected by the resolved
    // wildcards:
    // - if $r is `<p class> <$text-container class="foo">`
    // - then $naive will be `<p class="foo">`
    // - merging them yields `<p class> <$text-container class="foo">`
    //   again
    // - diffing the wildcard subsets yields just `<p class>`
    return $r->merge($naive_resolution)
        ->doDiff($r->getWildcardSubset());
}

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