summaryrefslogtreecommitdiffstats
path: root/core/modules/media/tests/modules/media_test_source/src/Plugin/Validation/Constraint/MediaTestConstraintValidator.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/modules/media/tests/modules/media_test_source/src/Plugin/Validation/Constraint/MediaTestConstraintValidator.php')
-rw-r--r--core/modules/media/tests/modules/media_test_source/src/Plugin/Validation/Constraint/MediaTestConstraintValidator.php34
1 files changed, 34 insertions, 0 deletions
diff --git a/core/modules/media/tests/modules/media_test_source/src/Plugin/Validation/Constraint/MediaTestConstraintValidator.php b/core/modules/media/tests/modules/media_test_source/src/Plugin/Validation/Constraint/MediaTestConstraintValidator.php
new file mode 100644
index 0000000..1c74443
--- /dev/null
+++ b/core/modules/media/tests/modules/media_test_source/src/Plugin/Validation/Constraint/MediaTestConstraintValidator.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace Drupal\media_test_source\Plugin\Validation\Constraint;
+
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Field\FieldItemListInterface;
+use Symfony\Component\Validator\Constraint;
+use Symfony\Component\Validator\ConstraintValidator;
+
+/**
+ * Validates the MediaTestConstraint.
+ */
+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);
+ }
+ }
+
+}