function IntegerItem::getConstraints

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Field/Plugin/Field/FieldType/IntegerItem.php \Drupal\Core\Field\Plugin\Field\FieldType\IntegerItem::getConstraints()
  2. 10 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/IntegerItem.php \Drupal\Core\Field\Plugin\Field\FieldType\IntegerItem::getConstraints()
  3. 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 62

Class

IntegerItem
Defines the 'integer' field type.

Namespace

Drupal\Core\Field\Plugin\Field\FieldType

Code

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' => $this->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.