Issue Feature Closed

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

Stephan Bauer 01/06/22, 23:20 updated 02/19/26, 21:24

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.');
     }

     /**

Reviews 2

History 713

  1. Georg Ringer commented and changed status New Needs Feedback <span data-processor="relativetime" data-value="2022-01-10T14:11:34+00:00" > 01/10/22, 14:11 </span>

    Thanks for creating this feature request.
    The big issue I see is this will produce a non working output as you need some cookie consent solution which covers:

    • tell user about third party content
    • checking if user allows this type of content
    • JS to change the data-src back to src.

    especially because TYPO3 does not (yet) ship any frontend and because there are multiple extensions outthere providing everything already I am unsure if this issue can be set to closed?

  2. Stephan Bauer commented <span data-processor="relativetime" data-value="2022-01-10T16:00:32+00:00" > 01/10/22, 16:00 </span>

    Thanks for your feedback.

    For me the media VH is not usable anymore because media links like youtube are loaded immediately and there is no way to block this. This is against GDPR.
    I would like to have a solution for this in the core.

    There are already some changes made so that the core is compatible with GDPR.

    With this option I could use core functionalities.

    I dont’ think that it is necessary to include an extenstion like dp_cookieconsent into the core.

  3. Georg Ringer commented and changed status Needs Feedback Accepted <span data-processor="relativetime" data-value="2022-01-11T08:21:29+00:00" > 01/11/22, 08:21 </span>

    thanks for your feedback!

  4. Gerrit Code Review pushed patch set 1 for main to change 80514 status Accepted Under Review <span data-processor="relativetime" data-value="2023-08-10T19:19:22+00:00" > 08/10/23, 19:19 </span>

  5. Max Frerichs commented <span data-processor="relativetime" data-value="2023-08-10T19:20:49+00:00" > 08/10/23, 19:20 </span>

    Georg Ringer wrote in #note-1:
    > Thanks for creating this feature request.
    > The big issue I see is this will produce a non working output as you need some cookie consent solution which covers:
    >
    > * tell user about third party content
    > * checking if user allows this type of content
    > * JS to change the data-src back to src.
    >
    > especially because TYPO3 does not (yet) ship any frontend and because there are multiple extensions outthere providing everything already I am unsure if this issue can be set to closed?

    I agree with you that adding an option like that could break output in frontend without proper client-side handling through JavaScript, but imho it makes sense to provide integrators / developers with an option to use data-src attribute instead of src attribute, especially for external-loaded media like YouTube or Vimeo.

    Maybe an additional optional argument with proper default values in media VH (something like data-src), evauluated in YouTubeRenderer.php and VimeoRenderer.php, that render some iframe, can solve this issue.
    I’ve uploaded a patchset. Feedback is appreciated!