public function SoundcloudForm::validateSoundcloudUrl in Media entity Soundcloud 8.2
Same name and namespace in other branches
- 3.x src/Form/SoundcloudForm.php \Drupal\media_entity_soundcloud\Form\SoundcloudForm::validateSoundcloudUrl()
Validates a soundcloud url.
Parameters
array $form: The form.
FormStateInterface $form_state: The form state.
Return value
void|TRUE
File
- src/
Form/ SoundcloudForm.php, line 114
Class
Namespace
Drupal\media_entity_soundcloud\FormCode
public function validateSoundcloudUrl(array &$form, FormStateInterface $form_state) {
$url = $form_state
->getValue('soundcloud_url');
if (preg_match('/https?:\\/\\/(www\\.)?soundcloud\\.com\\/.*/', $url)) {
try {
\Drupal::httpClient()
->get($url);
} catch (ClientException $e) {
$form_state
->setErrorByName('url', $this
->t('Could not connect to the track, please make sure that the url is correct.'));
}
}
else {
$form_state
->setErrorByName('url', $this
->t('Invalid url.'));
}
}