protected function Max::getRules in Clientside Validation 3.0.x
Same name and namespace in other branches
- 8.2 src/Plugin/CvValidator/Max.php \Drupal\clientside_validation\Plugin\CvValidator\Max::getRules()
- 8 src/Plugin/CvValidator/Max.php \Drupal\clientside_validation\Plugin\CvValidator\Max::getRules()
- 2.0.x src/Plugin/CvValidator/Max.php \Drupal\clientside_validation\Plugin\CvValidator\Max::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/ Max.php, line 24
Class
- Max
- Provides a 'max' validator.
Namespace
Drupal\clientside_validation\Plugin\CvValidatorCode
protected function getRules($element, FormStateInterface $form_state) {
$message = $element['#max_error'] ?? $this
->t('The value in @title has to be less than @max.', [
'@title' => $this
->getElementTitle($element),
'@max' => $this
->getAttributeValue($element, 'max'),
]);
// Drupal already adds the max attribute, so we don't need to set the max
// rule.
return [
'messages' => [
'max' => $message,
],
];
}