You are here

public function AddressItem::getConstraints in Address 8

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

src/Plugin/Field/FieldType/AddressItem.php, line 313

Class

AddressItem
Plugin implementation of the 'address' field type.

Namespace

Drupal\address\Plugin\Field\FieldType

Code

public function getConstraints() {
  $constraints = parent::getConstraints();
  $constraint_manager = $this
    ->getTypedDataManager()
    ->getValidationConstraintManager();
  $field_overrides = new FieldOverrides($this
    ->getFieldOverrides());
  $constraints[] = $constraint_manager
    ->create('ComplexData', [
    'country_code' => [
      'Country' => [
        'availableCountries' => $this
          ->getAvailableCountries(),
      ],
    ],
  ]);
  $constraints[] = $constraint_manager
    ->create('AddressFormat', [
    'fieldOverrides' => $field_overrides,
  ]);
  return $constraints;
}