function StyleSensibleElementConstraintValidator::findStyleConflictingPluginLabel
Same name in other branches
- 9 core/modules/ckeditor5/src/Plugin/Validation/Constraint/StyleSensibleElementConstraintValidator.php \Drupal\ckeditor5\Plugin\Validation\Constraint\StyleSensibleElementConstraintValidator::findStyleConflictingPluginLabel()
- 10 core/modules/ckeditor5/src/Plugin/Validation/Constraint/StyleSensibleElementConstraintValidator.php \Drupal\ckeditor5\Plugin\Validation\Constraint\StyleSensibleElementConstraintValidator::findStyleConflictingPluginLabel()
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.
File
-
core/
modules/ ckeditor5/ src/ Plugin/ Validation/ Constraint/ StyleSensibleElementConstraintValidator.php, line 194
Class
- StyleSensibleElementConstraintValidator
- Styles can only be specified for HTML5 tags and extra classes.
Namespace
Drupal\ckeditor5\Plugin\Validation\ConstraintCode
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();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.