You are here

public static function PlatformBase::validateValue in Social Media Links Block and Field 8.2

Validates the user input of a platform before the value is saved.

Return value

mixed The result of the validation.

Overrides PlatformInterface::validateValue

3 methods override PlatformBase::validateValue()
Email::validateValue in src/Plugin/SocialMediaLinks/Platform/Email.php
Validates the user input of a platform before the value is saved.
Tumblr::validateValue in src/Plugin/SocialMediaLinks/Platform/Tumblr.php
Validates the user input of a platform before the value is saved.
Website::validateValue in src/Plugin/SocialMediaLinks/Platform/Website.php
Validates the user input of a platform before the value is saved.

File

src/PlatformBase.php, line 106

Class

PlatformBase
Base class for platform.

Namespace

Drupal\social_media_links

Code

public static function validateValue(array &$element, FormStateInterface $form_state, array $form) {

  // Do not allow a URL when the plugin already provides a URL prefix.
  if (!empty($element['#value']) && !empty($element['#field_prefix'])) {
    if (UrlHelper::isExternal($element['#value'])) {
      $form_state
        ->setError($element, t("The entered value %value is a URL. You should enter only the relative part, the URL prefix is automatically prepended.", [
        '%value' => $element['#value'],
      ]));
    }
  }
}