public function CpfItem::getConstraints in CPF 8.2
Same name and namespace in other branches
- 8 src/Plugin/Field/FieldType/CpfItem.php \Drupal\cpf\Plugin\Field\FieldType\CpfItem::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
- src/
Plugin/ Field/ FieldType/ CpfItem.php, line 138 - Contains \Drupal\cpf\Plugin\Field\FieldType\CpfItem.
Class
- CpfItem
- Plugin implementation of the 'cpf' field type.
Namespace
Drupal\cpf\Plugin\Field\FieldTypeCode
public function getConstraints() {
$constraints = parent::getConstraints();
$unique = $this
->getSetting('unique');
$value_constraints = [];
$value_constraints['CpfValue'] = [];
if ($unique == static::UNIQUE_VALUES) {
$value_constraints['CpfUnique'] = [
'fieldDefinition' => $this
->getFieldDefinition(),
'ignoreBundle' => $this
->getSetting('ignore_bundle'),
'entity' => $this
->getEntity(),
];
}
$constraint_manager = \Drupal::typedDataManager()
->getValidationConstraintManager();
$constraints[] = $constraint_manager
->create('ComplexData', [
'value' => $value_constraints,
]);
return $constraints;
}