Provide sub-module to allow contextual consent for oEmbedded content

Created on 20 January 2022, about 3 years ago
Updated 21 December 2022, about 2 years ago

Klaro provides a feature called "contextual consent", which enables you to ask for the users' consent before showing e.g. embedded Youtube videos or other content. Simple Klaro should implement this feature when e.g. Youtube videos get rendered via core's "oEmbed content" media formatter.

1.1. Get the oEmbedded provider name e.g. youtube.
1.2. Check Simple Klaro config if a service with the same name has been defined.
1.3. If so, and if current user doesn't have the bypass simple klaro permission swap the iframe's src attribute with data-src and provide a data-name attribute with the provider name to have Klaro's "contextual consent" fire.

Important to know is, that core Media's field formatter renders the content in two iframes for security reasons, see this code comment: Link to code comment. So you'll have an iframe and inside this iframe is another iframe with the actual content e.g. the Youtube player. Challenge is that because of this two-iframes approach Klaro can't simply find the actual iframe where the attributes adjusting need to happen, as Klaro only looks for first-level iframes.

So you need to get Klaro into the first iframe somehow. By default only CSS gets attached for media-oembed-iframe.html.twig.

Attaching JS placeholders and Simple Klaro from inside hook_preprocess_media_oembed_iframe is no choice because the render array is only used for markup while attachments get attached to a response which fetches the inner iframe. So we'll need a new field formatter to call a new route, and a new controller for rendering and attaching the right placeholders and libraries.

2.1. Provide new oEmbed field formatter.
2.2. Provide new route that gets called inside the new formatter.
2.3. Provide new oEmbed iframe controller to attach the JS placeholders and the Simple Klaro library conditionally (service and permission check, see 1.2. and 1.3).

After done that, because of the inner iframe creating a complete new render context the consent banner gets rendered twice: First in the main window, second in the outer iframe and submitting the main banner has no effect on the second banner or contextual consent, only after reloading the page.

3.1. Prevent the main banner from getting rendered twice, maybe by URL (if URL equals /simple-klaro/oembed stop).
3.2. Reload the iframe when the consent (from the main cookie banner or by updating the consent later) is changed to prevent needing to reload the whole page.

Feature request
Status

Needs work

Version

1.0

Component

Code

Created by

leymannx Berlin

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.

No activities found.

Production build 0.71.5 2024