From 614971024c2b02c64deae2de72f81d6b9a226f2e Mon Sep 17 00:00:00 2001 From: Seth Fisher Date: Tue, 20 Feb 2018 22:52:20 -0500 Subject: [PATCH] YT Playlist Parameter Additions * Added autoplay, start, and index params to YT PL * Add YT Playlist params to FieldOutputTest Autoplay, start, and index --- .../Provider/YouTubePlaylist.php | 27 ++++++ tests/src/Kernel/FieldOutputTest.php | 87 +++++++++++++++++++ 2 files changed, 114 insertions(+) diff --git a/src/Plugin/video_embed_field/Provider/YouTubePlaylist.php b/src/Plugin/video_embed_field/Provider/YouTubePlaylist.php index 1043c5a..0bea2cf 100644 --- a/src/Plugin/video_embed_field/Provider/YouTubePlaylist.php +++ b/src/Plugin/video_embed_field/Provider/YouTubePlaylist.php @@ -24,6 +24,9 @@ public function renderEmbedCode($width, $height, $autoplay) { '#url' => 'https://www.youtube.com/embed/videoseries', '#query' => [ 'list' => $this->getVideoId(), + 'autoplay' => $autoplay, + 'start' => $this->getTimeIndex(), + 'index' => $this->getVideoPositionIndex(), ], '#attributes' => [ 'width' => $width, @@ -33,6 +36,30 @@ public function renderEmbedCode($width, $height, $autoplay) { ], ]; } + + /** + * Get the time index for when the given playlist video starts. + * + * @return int + * The time index where the playlist video should start based on the URL. + */ + protected function getTimeIndex() { + preg_match('/[&\?]t=(?\d+)/', $this->getInput(), $matches); + return isset($matches['timeindex']) ? $matches['timeindex'] : 0; + } + + /** + * Get the position index of the video with which the given playlist should + * start. + * + * @return int + * The position index of the video with which the playlist should start + * based on the URL. + */ + protected function getVideoPositionIndex() { + preg_match('/[&\?]index=(?\d+)/', $this->getInput(), $matches); + return isset($matches['position_index']) ? $matches['position_index'] : 0; + } /** * {@inheritdoc} diff --git a/tests/src/Kernel/FieldOutputTest.php b/tests/src/Kernel/FieldOutputTest.php index 5ce00a5..4cb5eff 100644 --- a/tests/src/Kernel/FieldOutputTest.php +++ b/tests/src/Kernel/FieldOutputTest.php @@ -490,6 +490,93 @@ public function renderedFieldTestCases() { '#url' => 'https://www.youtube.com/embed/videoseries', '#query' => [ 'list' => 'PLpeDXSh4nHjQCIZmkxg3VSdpR5e87X5eB', + 'autoplay' => '1', + 'start' => '0', + 'index' => '0', + ], + '#attributes' => [ + 'width' => '100', + 'height' => '100', + 'frameborder' => '0', + 'allowfullscreen' => 'allowfullscreen', + ], + '#cache' => [ + 'contexts' => [ + 'user.permissions', + ], + ], + ], + ], + ], + 'YouTube Playlist: Time-index Embed Code' => [ + 'https://www.youtube.com/watch?v=xoJH3qZwsHc&list=PLpeDXSh4nHjQCIZmkxg3VSdpR5e87X5eB&t=100', + [ + 'type' => 'video_embed_field_video', + 'settings' => [ + 'width' => 100, + 'height' => 100, + 'autoplay' => TRUE, + 'responsive' => FALSE, + ], + ], + [ + '#type' => 'container', + '#attributes' => [ + 'class' => [ + 'video-embed-field-provider-youtube-playlist', + ], + ], + 'children' => [ + '#type' => 'video_embed_iframe', + '#provider' => 'youtube_playlist', + '#url' => 'https://www.youtube.com/embed/videoseries', + '#query' => [ + 'list' => 'PLpeDXSh4nHjQCIZmkxg3VSdpR5e87X5eB', + 'autoplay' => '1', + 'start' => '100', + 'index' => '0', + ], + '#attributes' => [ + 'width' => '100', + 'height' => '100', + 'frameborder' => '0', + 'allowfullscreen' => 'allowfullscreen', + ], + '#cache' => [ + 'contexts' => [ + 'user.permissions', + ], + ], + ], + ], + ], + 'YouTube Playlist: Position-index Embed Code' => [ + 'https://www.youtube.com/watch?v=xoJH3qZwsHc&list=PLpeDXSh4nHjQCIZmkxg3VSdpR5e87X5eB&index=5', + [ + 'type' => 'video_embed_field_video', + 'settings' => [ + 'width' => 100, + 'height' => 100, + 'autoplay' => TRUE, + 'responsive' => FALSE, + ], + ], + [ + '#type' => 'container', + '#attributes' => [ + 'class' => [ + 'video-embed-field-provider-youtube-playlist', + ], + ], + 'children' => [ + '#type' => 'video_embed_iframe', + '#provider' => 'youtube_playlist', + '#url' => 'https://www.youtube.com/embed/videoseries', + '#query' => [ + 'list' => 'PLpeDXSh4nHjQCIZmkxg3VSdpR5e87X5eB', + 'autoplay' => '1', + 'start' => '0', + 'index' => '5', ], '#attributes' => [ 'width' => '100',