isWildcardAttributeName example

/** * Computes a regular expression for matching a wildcard attribute name. * * @param string $wildcard_attribute_name * The wildcard attribute name for which to compute a regular expression. * * @return string * The computed regular expression. */
  private static function getRegExForWildCardAttributeName(string $wildcard_attribute_name): string {
    assert(self::isWildcardAttributeName($wildcard_attribute_name));
    return '/^' . str_replace('*', '.*', $wildcard_attribute_name) . '$/';
  }

  /** * Gets the subset of allowed elements whose tags are wildcards. * * @return \Drupal\ckeditor5\HTMLRestrictions * The subset of the given set of HTML restrictions. */
  public function getWildcardSubset(): HTMLRestrictions {
    return new self(array_filter($this->elements, [__CLASS__, 'isWildcardTag'], ARRAY_FILTER_USE_KEY));
  }
    // @see \Drupal\ckeditor5\HTMLRestrictions::validateAllowedRestrictionsPhase4()     // @see \Drupal\filter\Plugin\Filter\FilterHtml::getHTMLRestrictions()     $forbidden_attributes = [];
    if (array_key_exists('*', $text_format_allowed_elements)) {
      $forbidden_attributes = array_keys(array_filter($text_format_allowed_elements['*']function D$attribute_value_restriction, string $attribute_name) {
        return $attribute_value_restriction === FALSE;
      }, ARRAY_FILTER_USE_BOTH));
    }

    foreach ($forbidden_attributes as $forbidden_attribute_name) {
      // Forbidden attributes not containing wildcards, such as `style`.       if (!self::isWildcardAttributeName($forbidden_attribute_name)) {
        if (array_key_exists($forbidden_attribute_name$attribute_restrictions)) {
          $this->context->buildViolation($constraint->message)
            ->setParameter('%dangerous_tag', $value)
            ->addViolation();
        }
      }
      // Forbidden attributes containing wildcards such as `on*`.       else {
        $regex = self::getRegExForWildCardAttributeName($forbidden_attribute_name);
        if (!empty(preg_grep($regexarray_keys($attribute_restrictions)))) {
          $this->context->buildViolation($constraint->message)
            
Home | Imprint | This part of the site doesn't use cookies.