function IntegerItem::getConstraints
Same name in other branches
- 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/IntegerItem.php \Drupal\Core\Field\Plugin\Field\FieldType\IntegerItem::getConstraints()
- 10 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/IntegerItem.php \Drupal\Core\Field\Plugin\Field\FieldType\IntegerItem::getConstraints()
- 11.x core/lib/Drupal/Core/Field/Plugin/Field/FieldType/IntegerItem.php \Drupal\Core\Field\Plugin\Field\FieldType\IntegerItem::getConstraints()
Overrides NumericItemBase::getConstraints
File
-
core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldType/ IntegerItem.php, line 61
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', [
'value' => [
'Range' => [
'min' => 0,
'minMessage' => t('%name: The integer must be larger or equal to %min.', [
'%name' => $this->getFieldDefinition()
->getLabel(),
'%min' => 0,
]),
],
],
]);
}
return $constraints;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.