Posts

Use different image content for mobile and desktop in Drupal 8 (Art direction)

Bild
This tutorial shows how to create a reusable container to display different images dependent on the viewport width. Scenario The website should display a different image depending on the viewport size. These images are art-directed, which means they will differ in content and layout and are created specifically for desktop and mobile respectivly.  The goal is to have a reusable concept which allows using our existing image optimization pipelines, but will not include patching of existing components and will minimize site traffic. The solution should also work for Internet Explorer 11 ;( Serving both images and using CSS to hide one or the other, is out of the question as it will ultimately download both images. The picture element is a good start but rendering it manually would circumvent our existing image optimizations. Components We use the following components: Drupal 8 Paragraphs Module  (Optional) Responsive Images Module reSmush.it image style optimizer Module  (Op...

Embed videos GDPR (DSGVO) compliant in Drupal 8

Bild
The following tutorial shows you how to prevent embedded youtube or vimeo videos from loading in Drupal 8. As long as the user has not accepted cookies, a banner with a preview of the video is shown instead of the video. Live-Version Why? GDPR (DSGVO) requires you to introduce another click before the video loads. That is because youtube sets cookies even before the video is started. After the click, the video embedded code should load. Components For this sample the following components are used. Drupal 8 Video Embed Field Module  (optional, could be any moduleto embedded videos) EU Cookie Compliance Module (could be any module for cookies) Step 1: Prevent Youtube from loading. To prevent YoutTube from loading we have to replace the src attribute of the IFrame with a data-src attribute. If you have embedded the video manual, you can edit it. If you use the Video Embed Field Module you can override the template by creating the following twig file in yo...