public function IntegerItem::getConstraints in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/IntegerItem.php \Drupal\Core\Field\Plugin\Field\FieldType\IntegerItem::getConstraints()
Gets a list of validation constraints.
Return value
array Array of constraints, each being an instance of \Symfony\Component\Validator\Constraint.
Overrides NumericItemBase::getConstraints
File
- core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldType/ IntegerItem.php, line 66 - Contains \Drupal\Core\Field\Plugin\Field\FieldType\IntegerItem.
Class
- IntegerItem
- Defines the 'integer' field type.
Namespace
Drupal\Core\Field\Plugin\Field\FieldTypeCode
public function getConstraints() {
$constraints = parent::getConstraints();
// If this is an unsigned integer, add a validation constraint for the
// integer to be positive.
if ($this
->getSetting('unsigned')) {
$constraint_manager = \Drupal::typedDataManager()
->getValidationConstraintManager();
$constraints[] = $constraint_manager
->create('ComplexData', array(
'value' => array(
'Range' => array(
'min' => 0,
'minMessage' => t('%name: The integer must be larger or equal to %min.', array(
'%name' => $this
->getFieldDefinition()
->getLabel(),
'%min' => 0,
)),
),
),
));
}
return $constraints;
}