6a721ef56db179e3c3ccbc84f68d8eb7ed65ae31
[yaffs-website] / web / core / lib / Drupal / Core / Entity / Plugin / Validation / Constraint / EntityHasFieldConstraint.php
1 <?php
2
3 namespace Drupal\Core\Entity\Plugin\Validation\Constraint;
4
5 use Symfony\Component\Validator\Constraint;
6
7 /**
8  * Checks if a value is an entity that has a specific field.
9  *
10  * @Constraint(
11  *   id = "EntityHasField",
12  *   label = @Translation("Entity has field", context = "Validation"),
13  *   type = { "entity" },
14  * )
15  */
16 class EntityHasFieldConstraint extends Constraint {
17
18   /**
19    * The default violation message.
20    *
21    * @var string
22    */
23   public $message = 'The entity must have the %field_name field.';
24
25   /**
26    * The violation message for non-fieldable entities.
27    *
28    * @var string
29    */
30   public $notFieldableMessage = 'The entity does not support fields.';
31
32   /**
33    * The field name option.
34    *
35    * @var string
36    */
37   public $field_name;
38
39   /**
40    * {@inheritdoc}
41    */
42   public function getDefaultOption() {
43     return 'field_name';
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public function getRequiredOptions() {
50     return (array) $this->getDefaultOption();
51   }
52
53 }