You are here

public function OEmbedForm::validateUrl in Media Directories 8

Same name and namespace in other branches
  1. 3.x modules/media_directories_ui/src/Form/OEmbedForm.php \Drupal\media_directories_ui\Form\OEmbedForm::validateUrl()
  2. 2.x modules/media_directories_ui/src/Form/OEmbedForm.php \Drupal\media_directories_ui\Form\OEmbedForm::validateUrl()

Validates the oEmbed URL.

Parameters

array $form: The complete form.

\Drupal\Core\Form\FormStateInterface $form_state: The current form state.

File

modules/media_directories_ui/src/Form/OEmbedForm.php, line 153

Class

OEmbedForm
A form to add remote content using OEmbed resources.

Namespace

Drupal\media_directories_ui\Form

Code

public function validateUrl(array &$form, FormStateInterface $form_state) {
  $url = $form_state
    ->getValue('url');
  if ($url) {
    try {
      $resource_url = $this->urlResolver
        ->getResourceUrl($url);
      $this->resourceFetcher
        ->fetchResource($resource_url);
    } catch (ResourceException $e) {
      $form_state
        ->setErrorByName('url', $e
        ->getMessage());
    }
  }
}