function FundamentalCompatibilityConstraintValidator::checkHtmlRestrictionsMatch

Same name in other branches
  1. 9 core/modules/ckeditor5/src/Plugin/Validation/Constraint/FundamentalCompatibilityConstraintValidator.php \Drupal\ckeditor5\Plugin\Validation\Constraint\FundamentalCompatibilityConstraintValidator::checkHtmlRestrictionsMatch()
  2. 11.x core/modules/ckeditor5/src/Plugin/Validation/Constraint/FundamentalCompatibilityConstraintValidator.php \Drupal\ckeditor5\Plugin\Validation\Constraint\FundamentalCompatibilityConstraintValidator::checkHtmlRestrictionsMatch()

Checks the HTML restrictions match the enabled CKEditor 5 plugins' output.

Parameters

\Drupal\editor\EditorInterface $text_editor: The text editor to validate.

\Drupal\ckeditor5\Plugin\Validation\Constraint\FundamentalCompatibilityConstraint $constraint: The constraint to validate.

1 call to FundamentalCompatibilityConstraintValidator::checkHtmlRestrictionsMatch()
FundamentalCompatibilityConstraintValidator::validate in core/modules/ckeditor5/src/Plugin/Validation/Constraint/FundamentalCompatibilityConstraintValidator.php

File

core/modules/ckeditor5/src/Plugin/Validation/Constraint/FundamentalCompatibilityConstraintValidator.php, line 145

Class

FundamentalCompatibilityConstraintValidator
Validates fundamental compatibility of CKEditor 5 with the given text format.

Namespace

Drupal\ckeditor5\Plugin\Validation\Constraint

Code

private function checkHtmlRestrictionsMatch(EditorInterface $text_editor, FundamentalCompatibilityConstraint $constraint) : void {
    $html_restrictor_filters = static::getFiltersInFormatOfType($text_editor->getFilterFormat(), FilterInterface::TYPE_HTML_RESTRICTOR);
    $enabled_plugins = array_keys($this->pluginManager
        ->getEnabledDefinitions($text_editor));
    $provided_elements = $this->pluginManager
        ->getProvidedElements($enabled_plugins, $text_editor);
    $provided = new HTMLRestrictions($provided_elements);
    foreach ($html_restrictor_filters as $filter_plugin_id => $filter) {
        $allowed = HTMLRestrictions::fromFilterPluginInstance($filter);
        $diff_allowed = $allowed->diff($provided);
        $diff_elements = $provided->diff($allowed);
        if (!$diff_allowed->allowsNothing()) {
            $this->context
                ->buildViolation($constraint->notSupportedElementsMessage)
                ->setParameter('@list', implode(' ', $provided->toCKEditor5ElementsArray()))
                ->setParameter('@diff', implode(' ', $diff_allowed->toCKEditor5ElementsArray()))
                ->atPath("filters.{$filter_plugin_id}")
                ->addViolation();
        }
        if (!$diff_elements->allowsNothing()) {
            $this->context
                ->buildViolation($constraint->missingElementsMessage)
                ->setParameter('@list', implode(' ', $provided->toCKEditor5ElementsArray()))
                ->setParameter('@diff', implode(' ', $diff_elements->toCKEditor5ElementsArray()))
                ->atPath("filters.{$filter_plugin_id}")
                ->addViolation();
        }
    }
}

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