You are here

public static function SoundCloudWidget::validateSoundCloudUriElement in SoundCloud field 8

Form element validation handler for the 'url' element.

File

src/Plugin/Field/FieldWidget/SoundCloudWidget.php, line 105

Class

SoundCloudWidget
Plugin implementation of the 'soundcloud_url' widget.

Namespace

Drupal\soundcloudfield\Plugin\Field\FieldWidget

Code

public static function validateSoundCloudUriElement($element, FormStateInterface $form_state, $form) {
  $input = $element['#value'];
  if (!empty($input) && !preg_match('@^https?://soundcloud\\.com/([^"\\&]+)@i', $input, $matches)) {
    $form_state
      ->setError($element, t('Please provide a valid SoundCloud URL.'));
  }
}