You are here

class MediaTestConstraintValidator in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/media/tests/modules/media_test_source/src/Plugin/Validation/Constraint/MediaTestConstraintValidator.php \Drupal\media_test_source\Plugin\Validation\Constraint\MediaTestConstraintValidator

Validates the MediaTestConstraint.

Hierarchy

  • class \Drupal\media_test_source\Plugin\Validation\Constraint\MediaTestConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator

Expanded class hierarchy of MediaTestConstraintValidator

File

core/modules/media/tests/modules/media_test_source/src/Plugin/Validation/Constraint/MediaTestConstraintValidator.php, line 13

Namespace

Drupal\media_test_source\Plugin\Validation\Constraint
View source
class MediaTestConstraintValidator extends ConstraintValidator {

  /**
   * {@inheritdoc}
   */
  public function validate($value, Constraint $constraint) {
    if ($value instanceof EntityInterface) {
      $string_to_test = $value
        ->label();
    }
    elseif ($value instanceof FieldItemListInterface) {
      $string_to_test = $value->value;
    }
    else {
      return;
    }
    if (strpos($string_to_test, 'love Drupal') === FALSE) {
      $this->context
        ->addViolation($constraint->message);
    }
  }

}

Members