Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / lib / Drupal / Core / Entity / Plugin / Validation / Constraint / EntityHasFieldConstraint.php
diff --git a/web/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityHasFieldConstraint.php b/web/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityHasFieldConstraint.php
new file mode 100644 (file)
index 0000000..6a721ef
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+
+namespace Drupal\Core\Entity\Plugin\Validation\Constraint;
+
+use Symfony\Component\Validator\Constraint;
+
+/**
+ * Checks if a value is an entity that has a specific field.
+ *
+ * @Constraint(
+ *   id = "EntityHasField",
+ *   label = @Translation("Entity has field", context = "Validation"),
+ *   type = { "entity" },
+ * )
+ */
+class EntityHasFieldConstraint extends Constraint {
+
+  /**
+   * The default violation message.
+   *
+   * @var string
+   */
+  public $message = 'The entity must have the %field_name field.';
+
+  /**
+   * The violation message for non-fieldable entities.
+   *
+   * @var string
+   */
+  public $notFieldableMessage = 'The entity does not support fields.';
+
+  /**
+   * The field name option.
+   *
+   * @var string
+   */
+  public $field_name;
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getDefaultOption() {
+    return 'field_name';
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getRequiredOptions() {
+    return (array) $this->getDefaultOption();
+  }
+
+}