diff --git a/filter/mediaplugin/tests/filter_test.php b/filter/mediaplugin/tests/filter_test.php index 8a57f3cf25403..8b198da733bcc 100644 --- a/filter/mediaplugin/tests/filter_test.php +++ b/filter/mediaplugin/tests/filter_test.php @@ -95,9 +95,8 @@ function test_filter_mediaplugin_link() { 'Valid link
';
         $paddedurl = str_pad($originalurl, 6000, 'z');
         $validpaddedurl = '

Some text.


-
+
 
';
         $validpaddedurl = str_pad($validpaddedurl, 6000 + (strlen($validpaddedurl) - strlen($originalurl)), 'z');
 
diff --git a/media/player/youtube/lang/en/media_youtube.php b/media/player/youtube/lang/en/media_youtube.php
index 486292ce4bf22..f8834fcdeddd1 100644
--- a/media/player/youtube/lang/en/media_youtube.php
+++ b/media/player/youtube/lang/en/media_youtube.php
@@ -27,3 +27,5 @@
 $string['privacy:metadata'] = 'The Youtube media plugin does not store any personal data.';
 $string['supportsvideo'] = 'YouTube videos';
 $string['supportsplaylist'] = 'YouTube playlists';
+$string['nocookie'] = 'Use no cookie domain';
+$string['nocookie_desc'] = 'Use youtube-nocookie.com domain for embedding videos. This reduces the number of third party cookies used in embedding. This domain is also not blocked by some adblockers.';
diff --git a/media/player/youtube/settings.php b/media/player/youtube/settings.php
new file mode 100644
index 0000000000000..a92da22053f07
--- /dev/null
+++ b/media/player/youtube/settings.php
@@ -0,0 +1,36 @@
+.
+
+/**
+ * Settings file for plugin 'media_youtube'
+ *
+ * @package   media_youtube
+ * @copyright 2023 Matt Porritt fulltree) {
+    // Add the settings page.
+    $settings->add(new admin_setting_heading('media_youtube_settings',
+                    get_string('pluginname', 'media_youtube'),
+                    get_string('pluginname_help', 'media_youtube')));
+    // Add a settings checkbox to enable or disable no cookie YouTube links.
+    $settings->add(new admin_setting_configcheckbox('media_youtube/nocookie',
+        new lang_string('nocookie', 'media_youtube'),
+        new lang_string('nocookie_desc', 'media_youtube'), 0));
+}
diff --git a/media/player/youtube/templates/embed.mustache b/media/player/youtube/templates/embed.mustache
index f4f64fe56fe3f..ca49c401996ca 100644
--- a/media/player/youtube/templates/embed.mustache
+++ b/media/player/youtube/templates/embed.mustache
@@ -15,19 +15,19 @@
     along with Moodle.  If not, see .
 }}
 {{!
-    @template media/embed
+    @template media_youtube/embed
 
     This template will render the YouTube embeded player.
 
     Variables required for this template:
-    * info: The title of the video.
+    * title: The title of the video.
     * width: The width of the video.
     * height: The height of the video.
     * embedurl: The URL to the video.
 
     Example context (json):
     {
-        "info": "YouTube video",
+        "title": "YouTube video",
         "width": 640,
         "height": 360,
         "embedurl": "https://www.youtube.com/embed/9bZkp7q19f0?rel=0&wmode=transparent"
@@ -36,6 +36,6 @@
 }}
 
 
-
+
 
diff --git a/media/player/youtube/tests/player_test.php b/media/player/youtube/tests/player_test.php
index d50ec85f28df8..9dd77b1d41a75 100644
--- a/media/player/youtube/tests/player_test.php
+++ b/media/player/youtube/tests/player_test.php
@@ -184,4 +184,27 @@ public function test_embed_media() {
         $this->assertMatchesRegularExpression('~~', $content);
         $this->assertMatchesRegularExpression('~width="123" height="35"~', $content);
     }
+
+    /**
+     * Test that YouTube media plugin renders embed code correctly
+     * when the "nocookie" config options is set to true.
+     *
+     * @covers \media_youtube_plugin::embed_external
+     */
+    public function test_youtube_nocookie() {
+        // Turn on the no cookie option.
+        set_config('nocookie', true, 'media_youtube');
+
+        // Test that the embed code contains the no cookie domain.
+        $url = new \moodle_url('http://www.youtube.com/v/vyrwMmsufJc');
+        $text = \html_writer::link($url, 'Watch this one');
+        $content = format_text($text, FORMAT_HTML);
+        $this->assertMatchesRegularExpression('~youtube-nocookie~', $content);
+
+        // Next test for a playlist.
+        $url = new \moodle_url('https://www.youtube.com/playlist?list=PL59FEE129ADFF2B12');
+        $text = \html_writer::link($url, 'Great Playlist');
+        $content = format_text($text, FORMAT_HTML);
+        $this->assertMatchesRegularExpression('~youtube-nocookie~', $content);
+    }
 }
diff --git a/media/player/youtube/version.php b/media/player/youtube/version.php
index d1ef347adc5f4..52aa77e8c4e80 100644
--- a/media/player/youtube/version.php
+++ b/media/player/youtube/version.php
@@ -24,6 +24,6 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$plugin->version   = 2023042400;      // The current plugin version (Date: YYYYMMDDXX).
+$plugin->version   = 2023062400;      // The current plugin version (Date: YYYYMMDDXX).
 $plugin->requires  = 2023041800;      // Requires this Moodle version.
 $plugin->component = 'media_youtube'; // Full name of the plugin (used for diagnostics).