public function NumericItemBase::getConstraints in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/NumericItemBase.php \Drupal\Core\Field\Plugin\Field\FieldType\NumericItemBase::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
2 calls to NumericItemBase::getConstraints()
- DecimalItem::getConstraints in core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldType/ DecimalItem.php - Gets a list of validation constraints.
- IntegerItem::getConstraints in core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldType/ IntegerItem.php - Gets a list of validation constraints.
2 methods override NumericItemBase::getConstraints()
- DecimalItem::getConstraints in core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldType/ DecimalItem.php - Gets a list of validation constraints.
- IntegerItem::getConstraints in core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldType/ IntegerItem.php - Gets a list of validation constraints.
File
- core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldType/ NumericItemBase.php, line 80 - Contains \Drupal\Core\Field\Plugin\Field\FieldType\NumericItemBase.
Class
- NumericItemBase
- Base class for numeric configurable field types.
Namespace
Drupal\Core\Field\Plugin\Field\FieldTypeCode
public function getConstraints() {
$constraint_manager = \Drupal::typedDataManager()
->getValidationConstraintManager();
$constraints = parent::getConstraints();
$settings = $this
->getSettings();
$label = $this
->getFieldDefinition()
->getLabel();
if (!empty($settings['min'])) {
$min = $settings['min'];
$constraints[] = $constraint_manager
->create('ComplexData', array(
'value' => array(
'Range' => array(
'min' => $min,
'minMessage' => t('%name: the value may be no less than %min.', array(
'%name' => $label,
'%min' => $min,
)),
),
),
));
}
if (!empty($settings['max'])) {
$max = $settings['max'];
$constraints[] = $constraint_manager
->create('ComplexData', array(
'value' => array(
'Range' => array(
'max' => $max,
'maxMessage' => t('%name: the value may be no greater than %max.', array(
'%name' => $label,
'%max' => $max,
)),
),
),
));
}
return $constraints;
}