From a4fbbb414b1b1cb063763f1acf72c191c7149b0b Mon Sep 17 00:00:00 2001 From: bnjmnm Date: Fri, 2 Sep 2022 10:09:17 -0400 Subject: [PATCH] Issue #3231336 by Wim Leers, lauriii: Simplify HtmlRestrictions and FundamentalCompatibilityConstraintValidator now that "forbidden tags" are deprecated --- core/modules/ckeditor5/src/HTMLRestrictions.php | 9 +++------ .../FundamentalCompatibilityConstraintValidator.php | 9 +++++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/core/modules/ckeditor5/src/HTMLRestrictions.php b/core/modules/ckeditor5/src/HTMLRestrictions.php index e2de7c8394e..2da610ef5ad 100644 --- a/core/modules/ckeditor5/src/HTMLRestrictions.php +++ b/core/modules/ckeditor5/src/HTMLRestrictions.php @@ -305,7 +305,6 @@ final class HTMLRestrictions { * @return \Drupal\ckeditor5\HTMLRestrictions */ private static function unrestricted(): self { - // @todo Refine in https://www.drupal.org/project/drupal/issues/3231336, including adding support for all operations. $restrictions = HTMLRestrictions::emptySet(); $restrictions->unrestricted = TRUE; return $restrictions; @@ -334,16 +333,14 @@ final class HTMLRestrictions { throw new \InvalidArgumentException(); } - if ($object->getHtmlRestrictions() === FALSE) { - // @todo Refine in https://www.drupal.org/project/drupal/issues/3231336 + $restrictions = $object->getHTMLRestrictions(); + if ($restrictions === FALSE || $restrictions === []) { return self::unrestricted(); } - $restrictions = $object->getHTMLRestrictions(); - $allowed = $restrictions['allowed']; - // When allowing all tags on an attribute, transform FilterHtml output from // ['tag' => ['*'=> TRUE]] to ['tag' => TRUE] + $allowed = $restrictions['allowed']; foreach ($allowed as $element => $attributes) { if (is_array($attributes) && isset($attributes['*']) && $attributes['*'] === TRUE) { $allowed[$element] = TRUE; diff --git a/core/modules/ckeditor5/src/Plugin/Validation/Constraint/FundamentalCompatibilityConstraintValidator.php b/core/modules/ckeditor5/src/Plugin/Validation/Constraint/FundamentalCompatibilityConstraintValidator.php index 1cac8c16b15..16e54a8ed8f 100644 --- a/core/modules/ckeditor5/src/Plugin/Validation/Constraint/FundamentalCompatibilityConstraintValidator.php +++ b/core/modules/ckeditor5/src/Plugin/Validation/Constraint/FundamentalCompatibilityConstraintValidator.php @@ -119,12 +119,13 @@ class FundamentalCompatibilityConstraintValidator extends ConstraintValidator im * The constraint to validate. */ private function checkHtmlRestrictionsAreCompatible(FilterFormatInterface $text_format, FundamentalCompatibilityConstraint $constraint): void { - $fundamental = new HTMLRestrictions($this->pluginManager->getProvidedElements(self::FUNDAMENTAL_CKEDITOR5_PLUGINS)); - $html_restrictions = $text_format->getHtmlRestrictions(); - if (!isset($html_restrictions['allowed'])) { + $html_restrictions = HTMLRestrictions::fromTextFormat($text_format); + if ($html_restrictions->isUnrestricted()) { return; } - if (!$fundamental->diff(HTMLRestrictions::fromTextFormat($text_format))->allowsNothing()) { + + $fundamental = new HTMLRestrictions($this->pluginManager->getProvidedElements(self::FUNDAMENTAL_CKEDITOR5_PLUGINS)); + if (!$fundamental->diff($html_restrictions)->allowsNothing()) { $offending_filter = static::findHtmlRestrictorFilterNotAllowingTags($text_format, $fundamental); $this->context->buildViolation($constraint->nonAllowedElementsMessage) ->setParameter('%filter_label', (string) $offending_filter->getLabel())