You are here

protected function Email::getRules in Clientside Validation 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/CvValidator/Email.php \Drupal\clientside_validation\Plugin\CvValidator\Email::getRules()
  2. 3.0.x src/Plugin/CvValidator/Email.php \Drupal\clientside_validation\Plugin\CvValidator\Email::getRules()
  3. 2.0.x src/Plugin/CvValidator/Email.php \Drupal\clientside_validation\Plugin\CvValidator\Email::getRules()

Get the validation rules for this form element.

Return value

array An array with following keys:

  • rules: An array with the rulename as key and the rule arguments as value.
  • messages: An array with the rulename as key and the message for this rule as argument.

Overrides CvValidatorBase::getRules

File

src/Plugin/CvValidator/Email.php, line 26

Class

Email
Provides a 'email' validator.

Namespace

Drupal\clientside_validation\Plugin\CvValidator

Code

protected function getRules($element, FormStateInterface $form_state) {
  $message = $element['#email_error'] ?? $this
    ->t('@title does not contain a valid email.', [
    '@title' => $this
      ->getElementTitle($element),
  ]);
  return [
    'messages' => [
      'email' => $message,
    ],
  ];
}