function HTMLRestrictions::validateAllowedRestrictionsPhase3

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

Validates allowed elements — phase 3: HTML tag attribute restriction keys.

Parameters

array $elements: The allowed elements.

Throws

\InvalidArgumentException

1 call to HTMLRestrictions::validateAllowedRestrictionsPhase3()
HTMLRestrictions::__construct in core/modules/ckeditor5/src/HTMLRestrictions.php
Constructs a set of HTML restrictions.

File

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

Class

HTMLRestrictions
Represents a set of HTML restrictions.

Namespace

Drupal\ckeditor5

Code

private static function validateAllowedRestrictionsPhase3(array $elements) : void {
    foreach ($elements as $html_tag_name => $html_tag_restrictions) {
        if (!is_array($html_tag_restrictions)) {
            continue;
        }
        if (!Inspector::assertAllStrings(array_keys($html_tag_restrictions))) {
            throw new \InvalidArgumentException(sprintf('The "%s" HTML tag has attribute restrictions, but it is not an array of key-value pairs, with HTML tag attribute names as keys.', $html_tag_name));
        }
        foreach ($html_tag_restrictions as $html_tag_attribute_name => $html_tag_attribute_restrictions) {
            if (trim($html_tag_attribute_name) !== $html_tag_attribute_name) {
                throw new \InvalidArgumentException(sprintf('The "%s" HTML tag has an attribute restriction "%s" which contains whitespace. Omit the whitespace.', $html_tag_name, $html_tag_attribute_name));
            }
            if ($html_tag_attribute_name === '*') {
                throw new \InvalidArgumentException(sprintf('The "%s" HTML tag has an attribute restriction "*". This implies all attributes are allowed. Remove the attribute restriction instead, or use a prefix (`*-foo`), infix (`*-foo-*`) or suffix (`foo-*`) wildcard restriction instead.', $html_tag_name));
            }
        }
    }
}

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