Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UHF-5047: Cookie content blocker on TPR unit maps #566

Merged
merged 1 commit into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions hdbt.theme
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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';
}

/**
Expand Down
24 changes: 23 additions & 1 deletion templates/module/helfi_tpr/field--service-map-embed.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{{ element[0]['iframe'] }}
{% set link_url = element[0]['link']['#attributes']['href'] %}
{% set link_attributes = {
'class': [
Expand All @@ -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) }}