function ToolbarItemDependencyConstraintValidator::validate

Same name in other branches
  1. 9 core/modules/ckeditor5/src/Plugin/Validation/Constraint/ToolbarItemDependencyConstraintValidator.php \Drupal\ckeditor5\Plugin\Validation\Constraint\ToolbarItemDependencyConstraintValidator::validate()
  2. 11.x core/modules/ckeditor5/src/Plugin/Validation/Constraint/ToolbarItemDependencyConstraintValidator.php \Drupal\ckeditor5\Plugin\Validation\Constraint\ToolbarItemDependencyConstraintValidator::validate()

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\Constraint

Code

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.