Step.php in Clientside Validation 8.2
File
src/Plugin/CvValidator/Step.php
View source
<?php
namespace Drupal\clientside_validation\Plugin\CvValidator;
use Drupal\clientside_validation\CvValidatorBase;
use Drupal\Core\Form\FormStateInterface;
class Step extends CvValidatorBase {
protected function getRules($element, FormStateInterface $form_state) {
$step = $this
->getAttributeValue($element, 'step');
if ($step !== 'any') {
if (isset($element['#step_error'])) {
$message = $element['#step_error'];
}
elseif ($min = $this
->getAttributeValue($element, 'min')) {
$message = $this
->t('The value in @title has to be greater than @min by steps of @step.', [
'@title' => $this
->getElementTitle($element),
'@step' => $step,
'@min' => $min,
]);
}
else {
$message = $this
->t('The value in @title has to be divisible by @step.', [
'@title' => $this
->getElementTitle($element),
'@step' => $step,
]);
}
return [
'messages' => [
'step' => $message,
],
];
}
}
}
Classes
Name |
Description |
Step |
Provides a 'step' validator. |