You are here

public function EntityReferenceItem::getConstraints in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::getConstraints()

Gets a list of validation constraints.

Return value

array Array of constraints, each being an instance of \Symfony\Component\Validator\Constraint.

Overrides TypedData::getConstraints

File

core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php, line 160

Class

EntityReferenceItem
Defines the 'entity_reference' entity field type.

Namespace

Drupal\Core\Field\Plugin\Field\FieldType

Code

public function getConstraints() {
  $constraints = parent::getConstraints();

  // Remove the 'AllowedValuesConstraint' validation constraint because entity
  // reference fields already use the 'ValidReference' constraint.
  foreach ($constraints as $key => $constraint) {
    if ($constraint instanceof AllowedValuesConstraint) {
      unset($constraints[$key]);
    }
  }
  return $constraints;
}