Issue #3231336 by Wim Leers, lauriii: Simplify HtmlRestrictions and FundamentalCompatibilityConstraintValidator now that "forbidden tags" are deprecated
parent
accc4ee013
commit
a4fbbb414b
|
@ -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;
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in New Issue