Knock-out blazy iframes (GDPR / Cookies)

Created on 21 November 2022, over 1 year ago
Updated 22 March 2023, about 1 year ago

Problem/Motivation

Sorry to disturb here and not finding a solution myself yet, but I think I need help.

We're running into the following issue in cookies_video (submodule of https://www.drupal.org/project/cookies/ → ): #3322867: Blazy videos not blocked properly (src vs. data-src) →

When using Cookies in combination with blazy, the Video source is not successfully blocked if no consent is given.
What's needed is a reliable way to have all iframe src's blocked (via data-src) until consent is given.

I tried the following hooks:

/**
 * Alters Blazy individual item output to support a custom lightbox.
 *
 * @param array $build
 *   The renderable array of image/ video iframe being modified.
 * @param array $settings
 *   The available array of settings.
 *
 * @ingroup blazy_api
 */
function hook_blazy_alter(array &$build, array $settings = []) {
  if (!empty($settings['media_switch']) && $settings['media_switch'] == 'photoswipe') {
    $build['#pre_render'][] = 'my_module_pre_render';
  }
}

/**
 * Alters Blazy outputs entirely to support a custom (quasy-)lightbox.
 *
 * In a case of ElevateZoom Plus, it adds a prefix large image preview before
 * the Blazy Grid elements by adding an extra #theme_wrappers via #pre_render
 * element.
 *
 * @param array $build
 *   The renderable array of the entire Blazy output being modified.
 * @param array $settings
 *   The available array of settings.
 *
 * @ingroup blazy_api
 */
function hook_blazy_build_alter(array &$build, array $settings = []) {
  // Since 2.6, non-configurable settings are mostly grouped under `blazies`.
  // For pre 2.6, please use $settings['NAME'] directly.
  $blazies = $settings['blazies'];

  // All (quasi-)lightboxes are put directly under $blazies for being unique.
  // This also allows a quasi-lightbox like ElevateZoomPlus inject its optionset
  // as its value: elevatezoomplus: responsive, etc.
  if ($blazies->get('colorbox') || $blazies->get('zooming')) {
    $build['#pre_render'][] = 'my_module_pre_render_build';
  }
}

but that doesn't seem to be the correct approach. Now I'm trying to add a further prerender function to the 'blazy' theme render array, but I'm also not sure, if that's the best and most safe way.

As all EU countries and further states / countries are affected by GDPR topic and cookie / third party blocking, I'd like to ask the blazy maintainers for help here.

Thanks a lot in advance!

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

💬 Support request
Status

Fixed

Version

2.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024