Commit f27477a3 authored by nikunjkotecha's avatar nikunjkotecha Committed by nikunj
Browse files

Issue #2902818 by nikunjkotecha, Leon Kessler, hocu: Grammatical error in messages

parent 330a039e
......@@ -25,9 +25,14 @@ class Pattern extends CvValidatorBase {
* {@inheritdoc}
*/
protected function getRules($element, FormStateInterface $form_state) {
$message = $element['#pattern_error'] ??
$this->t('@title does not meet the requirements.', [
'@title' => $this->getElementTitle($element),
]);
return [
'messages' => [
'pattern' => isset($element['#pattern_error']) ? $element['#pattern_error'] : $this->t('@title does not meet the requirements.', ['@title' => $this->getElementTitle($element)]),
'pattern' => $message,
],
];
}
......
......@@ -24,9 +24,14 @@ class Email extends CvValidatorBase {
* {@inheritdoc}
*/
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' => $this->t('@title does not contain a valid email.', ['@title' => $this->getElementTitle($element)]),
'email' => $message,
],
];
}
......
......@@ -22,14 +22,17 @@ class Max extends CvValidatorBase {
* {@inheritdoc}
*/
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' => $this->t('The value in @title has to be less than @max.', [
'@title' => $this->getElementTitle($element),
'@max' => $this->getAttributeValue($element, 'max'),
]),
'max' => $message,
],
];
}
......
......@@ -24,22 +24,25 @@ class MaxLength extends CvValidatorBase {
protected function getRules($element, FormStateInterface $form_state) {
// Drupal already adds the maxlength attribute, so we don't need to set the
// maxlength rule.
if (isset($element['#type']) && $element['#type'] == 'select') {
return [
'messages' => [
'maxlength' => $this->t('@title field can only have a maximum of @max values.', [
'@title' => $this->getElementTitle($element),
'@max' => $this->getAttributeValue($element, 'maxlength'),
]),
],
];
if (isset($element['#maxlength_error'])) {
$message = $element['#maxlength_error'];
}
elseif (isset($element['#type']) && $element['#type'] == 'select') {
$message = $this->t('@title field can only have a maximum of @max values.', [
'@title' => $this->getElementTitle($element),
'@max' => $this->getAttributeValue($element, 'maxlength'),
]);
}
else {
$message = $this->t('@title field has a maximum length of @max.', [
'@title' => $this->getElementTitle($element),
'@max' => $this->getAttributeValue($element, 'maxlength'),
]);
}
return [
'messages' => [
'maxlength' => $this->t('@title field has a maximum length of @max.', [
'@title' => $this->getElementTitle($element),
'@max' => $this->getAttributeValue($element, 'maxlength'),
]),
'maxlength' => $message,
],
];
}
......
......@@ -22,14 +22,17 @@ class Min extends CvValidatorBase {
* {@inheritdoc}
*/
protected function getRules($element, FormStateInterface $form_state) {
$message = $element['#min_error'] ??
$this->t('The value in @title has to be greater than @min.', [
'@title' => $this->getElementTitle($element),
'@min' => $this->getAttributeValue($element, 'min'),
]);
// Drupal already adds the min attribute, so we don't need to set the min
// rule.
return [
'messages' => [
'min' => $this->t('The value in @title has to be greater than @min.', [
'@title' => $this->getElementTitle($element),
'@min' => $this->getAttributeValue($element, 'min'),
]),
'min' => $message,
],
];
}
......
......@@ -42,9 +42,14 @@ class Required extends CvValidatorBase {
// Drupal already adds the required attribute, so we don't need to set the
// required rule.
if ($is_required || $is_conditionally_required) {
$message = $element['#required_error'] ??
$this->t('@title is required.', [
'@title' => $this->getElementTitle($element),
]);
return [
'messages' => [
'required' => isset($element['#required_error']) ? $element['#required_error'] : $this->t('@title is required.', ['@title' => $this->getElementTitle($element)]),
'required' => $message,
],
];
}
......
......@@ -24,23 +24,26 @@ class Step extends CvValidatorBase {
protected function getRules($element, FormStateInterface $form_state) {
$step = $this->getAttributeValue($element, 'step');
if ($step !== 'any') {
if (($min = $this->getAttributeValue($element, 'min'))) {
return [
'messages' => [
'step' => $this->t('The value in @title has to be greater than @min by steps of @step.', [
'@title' => $this->getElementTitle($element),
'@step' => $step,
'@min' => $min,
]),
],
];
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' => $this->t('The value in @title has to be divisible by @step.', [
'@title' => $this->getElementTitle($element),
'@step' => $step,
]),
'step' => $message,
],
];
}
......
......@@ -24,9 +24,14 @@ class Url extends CvValidatorBase {
* {@inheritdoc}
*/
protected function getRules($element, FormStateInterface $form_state) {
$message = $element['#url_error'] ??
$this->t('@title does not contain a valid url.', [
'@title' => $this->getElementTitle($element),
]);
return [
'messages' => [
'url' => $this->t('@title does not contain a valid url.', ['@title' => $this->getElementTitle($element)]),
'url' => $message,
],
];
}
......
......@@ -25,9 +25,14 @@ class UrlInternalExternal extends CvValidatorBase {
* {@inheritdoc}
*/
protected function getRules($element, FormStateInterface $form_state) {
$message = $element['#url_internal_external_error'] ??
$this->t('@title does not contain a valid url.', [
'@title' => $this->getElementTitle($element),
]);
return [
'messages' => [
'pattern' => $this->t('@title does not contain a valid url.', ['@title' => $this->getElementTitle($element)]),
'pattern' => $message,
],
];
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment