You are here

public static function Email::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 PlatformBase::validateValue

File

src/Plugin/SocialMediaLinks/Platform/Email.php, line 29

Class

Email
Provides 'email' platform.

Namespace

Drupal\social_media_links\Plugin\SocialMediaLinks\Platform

Code

public static function validateValue(array &$element, FormStateInterface $form_state, array $form) {
  if (!empty($element['#value'])) {
    $validator = \Drupal::service('email.validator');
    if (!$validator
      ->isValid($element['#value'])) {
      $form_state
        ->setError($element, t('The entered email address is not valid.'));
    }
  }
}