class ToolbarItemConstraintValidator in Drupal 10
Toolbar item constraint validator.
@internal
Hierarchy
- class \Drupal\ckeditor5\Plugin\Validation\Constraint\ToolbarItemConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator implements ContainerInjectionInterface uses PluginManagerDependentValidatorTrait
Expanded class hierarchy of ToolbarItemConstraintValidator
File
- core/
modules/ ckeditor5/ src/ Plugin/ Validation/ Constraint/ ToolbarItemConstraintValidator.php, line 17
Namespace
Drupal\ckeditor5\Plugin\Validation\ConstraintView source
class ToolbarItemConstraintValidator extends ConstraintValidator implements ContainerInjectionInterface {
use PluginManagerDependentValidatorTrait;
/**
* {@inheritdoc}
*
* @throws \Symfony\Component\Validator\Exception\UnexpectedTypeException
* Thrown when the given constraint is not supported by this validator.
*/
public function validate($toolbar_item, Constraint $constraint) {
if (!$constraint instanceof ToolbarItemConstraint) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\ToolbarItem');
}
if ($toolbar_item === NULL) {
return;
}
if (!static::isValidToolbarItem($toolbar_item)) {
$this->context
->buildViolation($constraint->message)
->setParameter('%toolbar_item', $toolbar_item)
->setInvalidValue($toolbar_item)
->addViolation();
}
}
/**
* Validates the given toolbar item.
*
* @param string $toolbar_item
* A toolbar item as expected by CKEditor 5.
*
* @return bool
* Whether the given toolbar item is valid or not.
*/
protected function isValidToolbarItem(string $toolbar_item) : bool {
// Special case: the toolbar group separator.
// @see https://ckeditor.com/docs/ckeditor5/latest/features/toolbar/toolbar.html#separating-toolbar-items
if ($toolbar_item === '|') {
return TRUE;
}
// Special case: the breakpoint separator.
// @see https://ckeditor.com/docs/ckeditor5/latest/features/toolbar/toolbar.html#explicit-wrapping-breakpoint
if ($toolbar_item === '-') {
return TRUE;
}
$available_toolbar_items = array_keys($this->pluginManager
->getToolbarItems());
return in_array($toolbar_item, $available_toolbar_items, TRUE);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PluginManagerDependentValidatorTrait:: |
protected | property | The CKEditor 5 plugin manager. | |
PluginManagerDependentValidatorTrait:: |
public static | function | ||
PluginManagerDependentValidatorTrait:: |
private | function | Gets all disabled CKEditor 5 plugin definitions the user can enable. | |
PluginManagerDependentValidatorTrait:: |
private | function | Gets all other enabled CKEditor 5 plugin definitions. | |
PluginManagerDependentValidatorTrait:: |
public | function | Constructs a CKEditor5ConstraintValidatorTrait object. | |
ToolbarItemConstraintValidator:: |
protected | function | Validates the given toolbar item. | |
ToolbarItemConstraintValidator:: |
public | function |