You are here

public function TaxNumberItem::getConstraints in Commerce Core 8.2

Gets a list of validation constraints.

Return value

array Array of constraints, each being an instance of \Symfony\Component\Validator\Constraint.

Overrides TypedData::getConstraints

File

modules/tax/src/Plugin/Field/FieldType/TaxNumberItem.php, line 144

Class

TaxNumberItem
Plugin implementation of the 'commerce_tax_number' field type.

Namespace

Drupal\commerce_tax\Plugin\Field\FieldType

Code

public function getConstraints() {
  $constraints = parent::getConstraints();
  $max_length = 64;
  $constraint_manager = \Drupal::typedDataManager()
    ->getValidationConstraintManager();
  $constraints[] = $constraint_manager
    ->create('ComplexData', [
    'type' => [
      'AllowedValues' => [
        'choices' => $this
          ->getAllowedTypes(),
        'message' => $this
          ->t('Invalid type specified.'),
      ],
    ],
    'value' => [
      'Length' => [
        'max' => $max_length,
        'maxMessage' => $this
          ->t('%name: may not be longer than @max characters.', [
          '%name' => $this
            ->getFieldDefinition()
            ->getLabel(),
          '@max' => $max_length,
        ]),
      ],
    ],
    'verification_state' => [
      'AllowedValues' => [
        'choices' => [
          VerificationResult::STATE_SUCCESS,
          VerificationResult::STATE_FAILURE,
          VerificationResult::STATE_UNKNOWN,
        ],
        'message' => $this
          ->t('Invalid verification_state specified.'),
      ],
    ],
  ]);
  $constraints[] = $constraint_manager
    ->create('TaxNumber', [
    'verify' => $this
      ->getSetting('verify'),
    'allowUnverified' => $this
      ->getSetting('allow_unverified'),
  ]);
  return $constraints;
}