You are here

private function StyleSensibleElementConstraintValidator::findStyleConflictingPluginLabel in Drupal 10

Finds the plugin with elements that conflict with the style element.

Parameters

\Drupal\ckeditor5\HTMLRestrictions $needle: A style definition element: a single tag, plus the 'class' attribute, plus >=1 allowed 'class' attribute values.

Return value

\Drupal\Core\StringTranslation\TranslatableMarkup The label of the plugin that is conflicting with this style.

Throws

\OutOfBoundsException When a $needle is provided which does not exist among the other plugins.

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

File

core/modules/ckeditor5/src/Plugin/Validation/Constraint/StyleSensibleElementConstraintValidator.php, line 149

Class

StyleSensibleElementConstraintValidator
Styles can only be specified for HTML5 tags and extra classes.

Namespace

Drupal\ckeditor5\Plugin\Validation\Constraint

Code

private function findStyleConflictingPluginLabel(HTMLRestrictions $needle) : TranslatableMarkup {
  foreach ($this->pluginManager
    ->getDefinitions() as $id => $definition) {

    // We're looking to find the other plugin, not this one.
    if ($id === 'ckeditor5_style') {
      continue;
    }
    assert($definition instanceof CKEditor5PluginDefinition);
    if (!$definition
      ->hasElements()) {
      continue;
    }
    $haystack = HTMLRestrictions::fromString(implode($definition
      ->getElements()));
    if ($id === 'ckeditor5_sourceEditing') {

      // The Source Editing plugin's allowed elements are based on stored
      // config. This differs from all other plugins, which establish allowed
      // elements as part of their definition. Because of this, the $haystack
      // is calculated differently for Source Editing.
      $text_editor = $this
        ->createTextEditorObjectFromContext();
      $editor_plugins = $text_editor
        ->getSettings()['plugins'];
      if (!empty($editor_plugins['ckeditor5_sourceEditing'])) {
        $source_tags = $editor_plugins['ckeditor5_sourceEditing']['allowed_tags'];
        $haystack = HTMLRestrictions::fromString(implode($source_tags));
      }
    }
    if (self::intersectionWithClasses($needle, $haystack)) {
      return $definition
        ->label();
    }
  }
  throw new \OutOfBoundsException();
}