public function DynamicEntityReferenceFieldItemList::getConstraints in Dynamic Entity Reference 8
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldType/DynamicEntityReferenceFieldItemList.php \Drupal\dynamic_entity_reference\Plugin\Field\FieldType\DynamicEntityReferenceFieldItemList::getConstraints()
Gets a list of validation constraints.
Return value
array Array of constraints, each being an instance of \Symfony\Component\Validator\Constraint.
Overrides EntityReferenceFieldItemList::getConstraints
File
- src/
Plugin/ Field/ FieldType/ DynamicEntityReferenceFieldItemList.php, line 21
Class
- DynamicEntityReferenceFieldItemList
- Defines a item list class for dynamic entity reference fields.
Namespace
Drupal\dynamic_entity_reference\Plugin\Field\FieldTypeCode
public function getConstraints() {
$constraints = parent::getConstraints();
// Remove the 'ValidReferenceConstraint' validation constraint because
// dynamic entity reference fields already use the 'ValidDynamicReference'
// constraint.
foreach ($constraints as $key => $constraint) {
if ($constraint instanceof ValidReferenceConstraint) {
unset($constraints[$key]);
}
}
$constraints = array_values($constraints);
$constraint_manager = $this
->getTypedDataManager()
->getValidationConstraintManager();
$constraints[] = $constraint_manager
->create('ValidDynamicReference', []);
return $constraints;
}