You are here

public function ToolbarItemConstraintValidator::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/ToolbarItemConstraintValidator.php, line 27

Class

ToolbarItemConstraintValidator
Toolbar item constraint validator.

Namespace

Drupal\ckeditor5\Plugin\Validation\Constraint

Code

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();
  }
}