From 5ac5aaf35897ca9596eaab1844d26eff890e2e1c Mon Sep 17 00:00:00 2001 From: mmyllynen <4696381+dire@users.noreply.github.com> Date: Mon, 27 Feb 2023 15:17:07 +0200 Subject: [PATCH] UHF-5047: UHF-5047: Added the cookie content blocker to the maps on TPR unit pages. --- hdbt.theme | 9 +++++++ .../field--service-map-embed.html.twig | 24 ++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/hdbt.theme b/hdbt.theme index 14f4397b6..ced3da846 100644 --- a/hdbt.theme +++ b/hdbt.theme @@ -1262,6 +1262,12 @@ function hdbt_preprocess_field(&$variables) { $item['content']['#url']->setOption('attributes', $attributes); } break; + + case 'service_map_embed': + $url_parts = parse_url($variables['items'][0]['content']['iframe']['#attributes']['src']); + $variables['map_service_url'] = $url_parts['scheme'] . "://" . $url_parts['host']; + $variables['privacy_policy_url'] = _hdbt_eu_cookie_compliance_get_privacy_policy_url(); + break; } } @@ -1358,6 +1364,9 @@ function hdbt_preprocess_tpr_unit(&$variables) { // Add current Unit Url to variable. $variables['unit_url'] = !$entity->isNew() ? $entity->toUrl('canonical') : NULL; + + // Add cookie compliance JS to unit pages since they have maps. + $variables['#attached']['library'][] = 'hdbt/embedded-content-cookie-compliance'; } /** diff --git a/templates/module/helfi_tpr/field--service-map-embed.html.twig b/templates/module/helfi_tpr/field--service-map-embed.html.twig index 1965a5c19..ca42e70a9 100644 --- a/templates/module/helfi_tpr/field--service-map-embed.html.twig +++ b/templates/module/helfi_tpr/field--service-map-embed.html.twig @@ -1,4 +1,3 @@ -{{ element[0]['iframe'] }} {% set link_url = element[0]['link']['#attributes']['href'] %} {% set link_attributes = { 'class': [ @@ -7,4 +6,27 @@ ], 'target': '_blank', } %} +{% set iframe_attributes = element[0]['iframe']['#attributes'] %} + +{% include '@hdbt/misc/embedded-content-cookie-compliance.twig' with { + media_url: iframe_attributes['src'], + media_id: element['#object'].id.value, + media_service_url: map_service_url, + privacy_policy_url: privacy_policy_url, +} %} + +{% set drupal_settings = { + '#attached': { + 'drupalSettings': { + 'embedded_media_attributes': { + (element['#object'].id.value): { + 'src': iframe_attributes['src'], + 'title': iframe_attributes['title'], + 'type': 'map', + } + } + } + } +} %} +{{ drupal_settings }} {{ link(element[0]['link']['#value'], link_url, link_attributes) }}