public function Dimension::getConstraints in Dimension 8
Same name and namespace in other branches
- 2.1.x src/Plugin/Field/FieldType/Dimension.php \Drupal\dimension\Plugin\Field\FieldType\Dimension::getConstraints()
- 2.0.x src/Plugin/Field/FieldType/Dimension.php \Drupal\dimension\Plugin\Field\FieldType\Dimension::getConstraints()
Gets a list of validation constraints.
Return value
array Array of constraints, each being an instance of \Symfony\Component\Validator\Constraint.
Overrides DecimalItem::getConstraints
File
- src/
Plugin/ Field/ FieldType/ Dimension.php, line 219
Class
Namespace
Drupal\dimension\Plugin\Field\FieldTypeCode
public function getConstraints() {
$constraint_manager = Drupal::typedDataManager()
->getValidationConstraintManager();
$constraints = array();
foreach ($this->definition
->getConstraints() as $name => $options) {
$constraints[] = $constraint_manager
->create($name, $options);
}
/** @noinspection StaticInvocationViaThisInspection */
foreach ($this
->fields() as $key => $label) {
$settings = $this
->getSetting($key);
$constraints[] = $constraint_manager
->create('ComplexData', array(
$key => array(
'Regex' => array(
'pattern' => '/^[+-]?((\\d+(\\.\\d*)?)|(\\.\\d+))$/i',
),
),
));
if (!empty($settings['min'])) {
$min = $settings['min'];
$constraints[] = $constraint_manager
->create('ComplexData', array(
$key => array(
'Range' => array(
'min' => $min,
'minMessage' => $this
->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(
$key => array(
'Range' => array(
'max' => $max,
'maxMessage' => $this
->t('%name: the value may be no greater than %max.', array(
'%name' => $label,
'%max' => $max,
)),
),
),
));
}
}
return $constraints;
}