3 namespace Drupal\video_embed_field\Plugin\video_embed_field\Provider;
5 use Drupal\video_embed_field\ProviderPluginBase;
8 * A YouTube playlist video provider.
10 * @VideoEmbedProvider(
11 * id = "youtube_playlist",
12 * title = @Translation("YouTube Playlist")
15 class YouTubePlaylist extends ProviderPluginBase {
20 public function renderEmbedCode($width, $height, $autoplay) {
22 '#type' => 'video_embed_iframe',
23 '#provider' => 'youtube_playlist',
24 '#url' => 'https://www.youtube.com/embed/videoseries',
26 'list' => $this->getVideoId(),
32 'allowfullscreen' => 'allowfullscreen',
40 public function getRemoteThumbnailUrl() {
41 return sprintf('http://img.youtube.com/vi/%s/hqdefault.jpg', static::getUrlComponent($this->getInput(), 'video_id'));
47 public static function getIdFromInput($input) {
48 return static::getUrlComponent($input, 'id');
52 * Get a component from the URL.
54 * @param string $input
56 * @param string $component
57 * The component from the regex to get.
60 * The value of the match in the regex.
62 protected static function getUrlComponent($input, $component) {
63 preg_match('/^https?:\/\/(?:www\.)?youtube\.com\/watch\?(?=.*v=(?<video_id>[0-9A-Za-z_-]*))(?=.*list=(?<id>[A-Za-z0-9_-]*))/', $input, $matches);
64 return isset($matches[$component]) ? $matches[$component] : FALSE;