You are here

protected function Url::getRules in Clientside Validation 2.0.x

Same name and namespace in other branches
  1. 8.2 src/Plugin/CvValidator/Url.php \Drupal\clientside_validation\Plugin\CvValidator\Url::getRules()
  2. 8 src/Plugin/CvValidator/Url.php \Drupal\clientside_validation\Plugin\CvValidator\Url::getRules()
  3. 3.0.x src/Plugin/CvValidator/Url.php \Drupal\clientside_validation\Plugin\CvValidator\Url::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/Url.php, line 26

Class

Url
Provides a 'url' validator.

Namespace

Drupal\clientside_validation\Plugin\CvValidator

Code

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' => $message,
    ],
  ];
}