Project

General

Profile

Actions

Feature #96477

open

Fluid media element - privacy option (loading after accepting a cookie)

Added by Stephan Bauer over 2 years ago. Updated 9 months ago.

Status:
Under Review
Priority:
Should have
Assignee:
-
Category:
Fluid
Target version:
-
Start date:
2022-01-07
Due date:
% Done:

0%

Estimated time:
PHP Version:
Tags:
Complexity:
Sprint Focus:

Description

Media elments link youtube videos should not load immediately because of ePrivacy etc.
The usually solution is to change the 'src' tag to 'data-src' and let some JS do the loading.
The only this that is missing is to define an option if you want 'data-src' or not.

With this little code it would be possible to use the media element:
(plus lazy loading which is supported by Chrome https://caniuse.com/?search=loading)

diff -ru typo3_src-10.4.22.orig/typo3/sysext/core/Classes/Resource/Rendering/YouTubeRenderer.php typo3_src-10.4.22/typo3/sysext/core/Classes/Resource/Rendering/YouTubeRenderer.php
--- typo3_src-10.4.22.orig/typo3/sysext/core/Classes/Resource/Rendering/YouTubeRenderer.php    2021-12-14 09:06:06.000000000 +0100
+++ typo3_src-10.4.22/typo3/sysext/core/Classes/Resource/Rendering/YouTubeRenderer.php    2022-01-07 00:05:37.000000000 +0100
@@ -95,8 +95,13 @@
         $src = $this->createYouTubeUrl($options, $file);
         $attributes = $this->collectIframeAttributes($width, $height, $options);

+        $privacy = "";
+        if ($options['privacy']) {
+            $privacy = "data-";
+        }
         return sprintf(
-            '<iframe src="%s"%s></iframe>',
+            '<iframe ' . $privacy . 'src="%s"%s></iframe>',
             htmlspecialchars($src, ENT_QUOTES | ENT_HTML5),
             empty($attributes) ? '' : ' ' . $this->implodeAttributes($attributes)
         );
@@ -209,7 +214,7 @@
         if (isset($GLOBALS['TSFE']) && is_object($GLOBALS['TSFE']) && (isset($GLOBALS['TSFE']->config['config']['doctype']) && $GLOBALS['TSFE']->config['config']['doctype'] !== 'html5')) {
             $attributes['frameborder'] = 0;
         }
-        foreach (['class', 'dir', 'id', 'lang', 'style', 'title', 'accesskey', 'tabindex', 'onclick', 'poster', 'preload', 'allow'] as $key) {
+        foreach (['class', 'dir', 'id', 'lang', 'style', 'title', 'accesskey', 'tabindex', 'onclick', 'poster', 'preload', 'allow', 'loading'] as $key) {
             if (!empty($options[$key])) {
                 $attributes[$key] = $options[$key];
             }
diff -ru typo3_src-10.4.22.orig/typo3/sysext/fluid/Classes/ViewHelpers/MediaViewHelper.php typo3_src-10.4.22/typo3/sysext/fluid/Classes/ViewHelpers/MediaViewHelper.php
--- typo3_src-10.4.22.orig/typo3/sysext/fluid/Classes/ViewHelpers/MediaViewHelper.php    2021-12-14 09:06:06.000000000 +0100
+++ typo3_src-10.4.22/typo3/sysext/fluid/Classes/ViewHelpers/MediaViewHelper.php    2022-01-06 23:52:27.000000000 +0100
@@ -87,6 +87,7 @@
         $this->registerArgument('cropVariant', 'string', 'select a cropping variant, in case multiple croppings have been specified or stored in FileReference', false, 'default');
         $this->registerArgument('fileExtension', 'string', 'Custom file extension to use for images');
         $this->registerArgument('loading', 'string', 'Native lazy-loading for images property. Can be "lazy", "eager" or "auto". Used on image files only.');
+        $this->registerArgument('privacy', 'string', 'Load media after a cookie is accepted.');
     }

     /**
Actions

Also available in: Atom PDF