class RegExValidationConstraintValidator in RegEx Field Validation 2.0.x
Same name and namespace in other branches
- 8 src/Plugin/Validation/Constraint/RegExValidationConstraintValidator.php \Drupal\regex_field_validation\Plugin\Validation\Constraint\RegExValidationConstraintValidator
- 1.0.x src/Plugin/Validation/Constraint/RegExValidationConstraintValidator.php \Drupal\regex_field_validation\Plugin\Validation\Constraint\RegExValidationConstraintValidator
Implementing Custom RegEx Validator Class.
Hierarchy
- class \Drupal\regex_field_validation\Plugin\Validation\Constraint\RegExValidationConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator
Expanded class hierarchy of RegExValidationConstraintValidator
File
- src/
Plugin/ Validation/ Constraint/ RegExValidationConstraintValidator.php, line 11
Namespace
Drupal\regex_field_validation\Plugin\Validation\ConstraintView source
class RegExValidationConstraintValidator extends ConstraintValidator {
/**
* {@inheritdoc}
*/
public function validate($items, Constraint $constraint) {
$field = $this->context
->getValue();
$value = $field
->getValue();
if (!empty($value)) {
if (!preg_match_all($constraint->regex, $value[0]['value'])) {
$this->context
->addViolation($this
->t($constraint->errorMessage));
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RegExValidationConstraintValidator:: |
public | function |