You are here

public function UrlToVideoFilterService::convertYouTubeUrls in URL to Video Filter 8

Same name and namespace in other branches
  1. 2.0.x src/Service/UrlToVideoFilterService.php \Drupal\url_to_video_filter\Service\UrlToVideoFilterService::convertYouTubeUrls()

Converts URLs to embedded YouTube videos.

Parameters

string $text: The text to be parsed for YouTube URLs.

Return value

array An array containing the following keys:

  • text: The text with the URLs replaced by the YouTube embed code
  • url_found: A boolean indicating whether any URLs were found in the given text.

Overrides UrlToVideoFilterServiceInterface::convertYouTubeUrls

File

src/Service/UrlToVideoFilterService.php, line 15

Class

UrlToVideoFilterService
Service class for the URL To Video Filter module.

Namespace

Drupal\url_to_video_filter\Service

Code

public function convertYouTubeUrls($text) {
  $return = [
    'text' => $text,
    'url_found' => FALSE,
  ];
  $urls = $this
    ->parseYouTubeUrls($text);
  if (count($urls)) {
    $return['url_found'] = TRUE;
    foreach ($urls as $url) {
      $embed_code = $this
        ->convertYouTubeUrlToEmbedCode($url);
      $return['text'] = str_replace($url, $embed_code, $return['text']);
    }
  }
  return $return;
}