3 namespace Drupal\Core\TypedData;
6 * A typed data definition class for the entity reference target_id property.
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.
12 * Validation for the target_id property is provided by the 'ValidReference'
13 * validation constraint.
15 * @see \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::preSave()
17 class DataReferenceTargetDefinition extends DataDefinition {
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']);