Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / rest / tests / modules / rest_test / src / Plugin / Validation / Constraint / RestTestConstraintValidator.php
1 <?php
2
3 namespace Drupal\rest_test\Plugin\Validation\Constraint;
4
5 use Drupal\Core\Field\FieldItemListInterface;
6 use Symfony\Component\Validator\Constraint;
7 use Symfony\Component\Validator\ConstraintValidator;
8
9 /**
10  * Validator for \Drupal\rest_test\Plugin\Validation\Constraint\RestTestConstraint.
11  */
12 class RestTestConstraintValidator extends ConstraintValidator {
13
14   /**
15    * {@inheritdoc}
16    */
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);
22       }
23     }
24   }
25
26 }