You are here

private function FundamentalCompatibilityConstraintValidator::checkHtmlRestrictionsMatch in Drupal 10

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 144

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 = $this->pluginManager
    ->getProvidedElements($enabled_plugins, $text_editor);
  foreach ($html_restrictor_filters as $filter_plugin_id => $filter) {
    $allowed = HTMLRestrictions::fromFilterPluginInstance($filter);
    $provided = new HTMLRestrictions($provided);
    $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();
    }
  }
}