public function ToolbarItemDependencyConstraintValidator::validate in Drupal 10
Throws
\Symfony\Component\Validator\Exception\UnexpectedTypeException Thrown when the given constraint is not supported by this validator.
File
- core/
modules/ ckeditor5/ src/ Plugin/ Validation/ Constraint/ ToolbarItemDependencyConstraintValidator.php, line 27
Class
- ToolbarItemDependencyConstraintValidator
- Toolbar item dependency constraint validator.
Namespace
Drupal\ckeditor5\Plugin\Validation\ConstraintCode
public function validate($toolbar_item, Constraint $constraint) {
if (!$constraint instanceof ToolbarItemDependencyConstraint) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\ToolbarItemDependency');
}
$toolbar_items = $this->context
->getRoot()
->get('settings.toolbar.items')
->toArray();
if (!in_array($constraint->toolbarItem, $toolbar_items, TRUE)) {
$this->context
->buildViolation($constraint->message)
->setParameter('%toolbar_item', $constraint->toolbarItem)
->addViolation();
}
}