public function EmailFieldValidationRule::validate in Field Validation 8
Overrides FieldValidationRuleBase::validate
File
- src/
Plugin/ FieldValidationRule/ EmailFieldValidationRule.php, line 61
Class
- EmailFieldValidationRule
- EmailFieldValidationRule.
Namespace
Drupal\field_validation\Plugin\FieldValidationRuleCode
public function validate($params) {
$value = isset($params['value']) ? $params['value'] : '';
$rule = isset($params['rule']) ? $params['rule'] : null;
$context = isset($params['context']) ? $params['context'] : null;
$settings = array();
if (!empty($rule) && !empty($rule->configuration)) {
$settings = $rule->configuration;
}
$pattern = isset($settings['setting']) ? $settings['setting'] : '';
//$settings = $this->rule->settings;
if ($value != '' && !\Drupal::service('email.validator')
->isValid($value)) {
$context
->addViolation($rule
->getErrorMessage());
}
}