You are here

protected function UrlInternalExternal::getRules in Clientside Validation 8

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

Class

UrlInternalExternal
Provides a 'url' validator for internal url.

Namespace

Drupal\clientside_validation\Plugin\CvValidator

Code

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