You are here

public function DecimalItem::getConstraints in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DecimalItem.php \Drupal\Core\Field\Plugin\Field\FieldType\DecimalItem::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/DecimalItem.php, line 93

Class

DecimalItem
Defines the 'decimal' field type.

Namespace

Drupal\Core\Field\Plugin\Field\FieldType

Code

public function getConstraints() {
  $constraint_manager = \Drupal::typedDataManager()
    ->getValidationConstraintManager();
  $constraints = parent::getConstraints();
  $constraints[] = $constraint_manager
    ->create('ComplexData', [
    'value' => [
      'Regex' => [
        'pattern' => '/^[+-]?((\\d+(\\.\\d*)?)|(\\.\\d+))$/i',
      ],
    ],
  ]);
  return $constraints;
}