Version 1
[yaffs-website] / web / core / lib / Drupal / Core / TypedData / DataReferenceTargetDefinition.php
1 <?php
2
3 namespace Drupal\Core\TypedData;
4
5 /**
6  * A typed data definition class for the entity reference target_id property.
7  *
8  * The target_id property differs from other data definitions in that it is
9  * required at the storage level, but not at the validation level. This is
10  * because its value can be set just-in-time using the preSave() method.
11  *
12  * Validation for the target_id property is provided by the 'ValidReference'
13  * validation constraint.
14  *
15  * @see \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::preSave()
16  */
17 class DataReferenceTargetDefinition extends DataDefinition {
18
19   /**
20    * {@inheritdoc}
21    */
22   public function getConstraints() {
23     $constraints = parent::getConstraints();
24     // If this data definition is marked as required for the sake of schema
25     // definitions, we don't enforce it using the NotNull constraint. Instead
26     // \Drupal\Core\Field\EntityReferenceItem is validated by the
27     // 'ValidReference' constraint that operates at the field-item level. This
28     // constraint takes into consideration that the target_id property can
29     // be derived from the entity property.
30     unset($constraints['NotNull']);
31     return $constraints;
32   }
33
34 }