class AddressFormatConstraintValidator in Address 8
Validates the address format constraint.
Hierarchy
- class \Drupal\address\Plugin\Validation\Constraint\AddressFormatConstraintValidator extends \CommerceGuys\Addressing\Validator\Constraints\AddressFormatConstraintValidator implements ContainerInjectionInterface
Expanded class hierarchy of AddressFormatConstraintValidator
File
- src/
Plugin/ Validation/ Constraint/ AddressFormatConstraintValidator.php, line 15
Namespace
Drupal\address\Plugin\Validation\ConstraintView source
class AddressFormatConstraintValidator extends ExternalValidator implements ContainerInjectionInterface {
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('address.address_format_repository'), $container
->get('address.subdivision_repository'));
}
/**
* {@inheritdoc}
*/
protected function addViolation($field, $message, $invalid_value, AddressFormat $address_format) {
$labels = LabelHelper::getFieldLabels($address_format);
$label = $labels[$field];
$this->context
->buildViolation($message, [
'@name' => $label,
])
->atPath(FieldHelper::getPropertyName($field))
->setInvalidValue($invalid_value)
->addViolation();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AddressFormatConstraintValidator:: |
protected | function | ||
AddressFormatConstraintValidator:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |