public function StateItem::getConstraints in State Machine 8
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
- src/
Plugin/ Field/ FieldType/ StateItem.php, line 73
Class
- StateItem
- Plugin implementation of the 'state' field type.
Namespace
Drupal\state_machine\Plugin\Field\FieldTypeCode
public function getConstraints() {
$constraints = parent::getConstraints();
// Replace the 'AllowedValuesConstraint' constraint with the 'State' one.
foreach ($constraints as $key => $constraint) {
if ($constraint instanceof AllowedValuesConstraint) {
unset($constraints[$key]);
}
}
$manager = \Drupal::typedDataManager()
->getValidationConstraintManager();
$constraints[] = $manager
->create('State', []);
return $constraints;
}