3 namespace Drupal\rest_test\Plugin\Validation\Constraint;
5 use Drupal\Core\Field\FieldItemListInterface;
6 use Symfony\Component\Validator\Constraint;
7 use Symfony\Component\Validator\ConstraintValidator;
10 * Validator for \Drupal\rest_test\Plugin\Validation\Constraint\RestTestConstraint.
12 class RestTestConstraintValidator extends ConstraintValidator {
17 public function validate($value, Constraint $constraint) {
18 if ($value instanceof FieldItemListInterface) {
19 $value = $value->getValue();
20 if (!empty($value[0]['value']) && $value[0]['value'] === 'ALWAYS_FAIL') {
21 $this->context->addViolation($constraint->message);