You are here

protected function EqualTo::getRules in Clientside Validation 8

Same name and namespace in other branches
  1. 8.2 clientside_validation_jquery/src/Plugin/CvValidator/EqualTo.php \Drupal\clientside_validation_jquery\Plugin\CvValidator\EqualTo::getRules()
  2. 3.0.x clientside_validation_jquery/src/Plugin/CvValidator/EqualTo.php \Drupal\clientside_validation_jquery\Plugin\CvValidator\EqualTo::getRules()
  3. 2.0.x clientside_validation_jquery/src/Plugin/CvValidator/EqualTo.php \Drupal\clientside_validation_jquery\Plugin\CvValidator\EqualTo::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

clientside_validation_jquery/src/Plugin/CvValidator/EqualTo.php, line 24

Class

EqualTo
Provides a 'equalTo' validator.

Namespace

Drupal\clientside_validation_jquery\Plugin\CvValidator

Code

protected function getRules($element, FormStateInterface $form_state) {
  $message = $element['#equal_to_error'] ?? $this
    ->t('Value in @field does not match.', [
    '@field' => $this
      ->getElementTitle($element),
  ]);
  return [
    'rules' => [
      'equalTo' => '[name="' . $element['#equal_to'] . '"]',
    ],
    'messages' => [
      'equalTo' => $message,
    ],
  ];
}