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-8650 Preparation for the HDS cookie banner module #1083

Merged
merged 26 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a36fea6
UHF-8650: Switch embeds and matomo to use hds cookie banner
Arkkimaagi Oct 11, 2024
6e13bb1
UHF-8650: Changed the name of the template to cookie-settings page.
khalima Oct 15, 2024
43fa49b
UHF-8650: Updated the cookie policy/settings URL to be retrieved from…
khalima Oct 15, 2024
8091313
UHF-8650: User cookie settings service to retrieve the privacy policy…
khalima Oct 21, 2024
da74773
UHF-8650: Added uninstall hook to remove all obsolete configurations.
khalima Oct 21, 2024
1c63cb6
UHF-8650: Use HDBT cookie banner cookie settings URL if available. Ot…
khalima Oct 21, 2024
0b30cde
UHF-8650: Check if privacy_policy_url exists.
khalima Oct 21, 2024
5f6efd7
UHF-8650: Added possibility to use the hdbt_cookie_banner settingsPag…
khalima Oct 21, 2024
341d4e7
UHF-8650: Added dist.
khalima Oct 21, 2024
96258df
UHF-8650: Fixed typo
khalima Oct 21, 2024
bb4fd53
UHF-8650: More consistend todo comments.
khalima Oct 21, 2024
ebc4fd4
UHF-8650: UHF-8650: Removed @var tag as PHPStan got confused of it.
khalima Oct 21, 2024
c6f2a0b
UHF-8650: More todo comments.
khalima Oct 21, 2024
5d00929
UHF-8650: Merge branch 'UHF-8650_cookie_banner_activation' of https:/…
khalima Oct 21, 2024
e511a11
UHF-8650: Switched to universal cookie consent status checker.
khalima Oct 22, 2024
ac6ebfa
UHF-8650: Added dist.
khalima Oct 22, 2024
60c2e8d
UHF-8650: UHF-8650: Use global Drupal.cookieConsent functions to chec…
khalima Oct 22, 2024
ada3982
UHF-8650: Added dist.
khalima Oct 22, 2024
f1d7add
UHF-8650: Change the way to load EU cookie compliance libraries to su…
khalima Oct 23, 2024
fffc260
UHF-8650: Merge branch 'UHF-8650' of https://github.com/City-of-Helsi…
khalima Oct 23, 2024
0631d2f
UHF-8650: Moved the window.hdsCookieConsentClickEvent to platform con…
khalima Oct 25, 2024
56f1740
UHF-8650: Added the cookie consent groups and onclick function to cha…
khalima Oct 25, 2024
ac3e4f1
UHF-8650: Added dist.
khalima Oct 25, 2024
5984e11
UHF-8650: Added onclick event for the askem (react and share) template.
khalima Oct 28, 2024
ab544b1
UHF-8650: Added fallback for the EU cookie compliance module.
khalima Oct 30, 2024
f8fe3ca
UHF-8650: Merge branch 'main' of https://github.com/City-of-Helsinki/…
khalima Oct 30, 2024
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
2 changes: 1 addition & 1 deletion dist/js/embedded-content-cookie-compliance.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/js/health-station-search.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/maternity-and-child-health-clinic-search.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/matomo.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/js/school-search.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions hdbt.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ matomo:
header: true
js:
dist/js/matomo.min.js: {
weight: -10,
minified: true
}
dependencies:
Expand Down
65 changes: 36 additions & 29 deletions hdbt.theme
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,15 @@ function hdbt_preprocess_field(&$variables): void {
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'] = helfi_eu_cookie_compliance_get_privacy_policy_url();

if (Drupal::moduleHandler()->moduleExists('hdbt_cookie_banner')) {
$cookie_settings = Drupal::service('hdbt_cookie_banner.cookie_settings');
$variables['privacy_policy_url'] = $cookie_settings->getCookieSettingsPageUrl();
}
// @todo UHF-10862 Remove once the HDBT cookie banner module is in use.
elseif (Drupal::moduleHandler()->moduleExists('helfi_eu_cookie_compliance')) {
$variables['privacy_policy_url'] = helfi_eu_cookie_compliance_get_privacy_policy_url();
}
break;
}
}
Expand Down Expand Up @@ -1719,41 +1727,35 @@ function hdbt_preprocess_paragraph__event_list(&$variables): void {
*/
function hdbt_preprocess_paragraph__school_search(array &$variables): void {
$variables['#attached']['library'][] = 'hdbt/school-search';

$privacyUrl = helfi_eu_cookie_compliance_get_privacy_policy_url();

if ($privacyUrl instanceof Url) {
$privacyUrl->setAbsolute();
$variables['#attached']['drupalSettings']['helfi_react_search']['cookie_privacy_url'] = $privacyUrl->toString();
}
// @todo UHF-10862 Remove once the HDBT cookie banner module is in use.
hdbt_set_legacy_privacy_policy_url($variables);
}

/**
* Implements hook_preprocess_HOOK().
*/
function hdbt_preprocess_paragraph__health_station_search(array &$variables): void {
$variables['#attached']['library'][] = 'hdbt/health-station-search';

$privacyUrl = helfi_eu_cookie_compliance_get_privacy_policy_url();

if ($privacyUrl instanceof Url) {
$privacyUrl->setAbsolute();
$variables['#attached']['drupalSettings']['helfi_react_search']['cookie_privacy_url'] = $privacyUrl->toString();
}
// @todo UHF-10862 Remove once the HDBT cookie banner module is in use.
hdbt_set_legacy_privacy_policy_url($variables);
}

/**
* Implements hook_preprocess_HOOK().
*/
function hdbt_preprocess_paragraph__maternity_and_child_health_clini(array &$variables): void {
$variables['#attached']['library'][] = 'hdbt/maternity-and-child-health-clinic-search';
// @todo UHF-10862 Remove once the HDBT cookie banner module is in use.
hdbt_set_legacy_privacy_policy_url($variables);
}

$privacyUrl = helfi_eu_cookie_compliance_get_privacy_policy_url();

if ($privacyUrl instanceof Url) {
$privacyUrl->setAbsolute();
$variables['#attached']['drupalSettings']['helfi_react_search']['cookie_privacy_url'] = $privacyUrl->toString();
}
/**
* Implements hook_preprocess_HOOK().
*/
function hdbt_preprocess_paragraph__ploughing_schedule(array &$variables): void {
$variables['#attached']['library'][] = 'hdbt/ploughing-schedule';
// @todo UHF-10862 Remove once the HDBT cookie banner module is in use.
hdbt_set_legacy_privacy_policy_url($variables);
}

/**
Expand Down Expand Up @@ -1888,15 +1890,20 @@ function hdbt_preprocess_views_exposed_form(array &$variables) {
}

/**
* Implements hook_preprocess_HOOK().
* Get privacy policy url from helfi_eu_cookie_compliance module.
*
* @todo UHF-10862 Remove once the HDBT cookie banner module is in use.
*
* @param array $variables
* Variables array.
*/
function hdbt_preprocess_paragraph__ploughing_schedule(array &$variables): void {
$variables['#attached']['library'][] = 'hdbt/ploughing-schedule';

$privacyUrl = helfi_eu_cookie_compliance_get_privacy_policy_url();
function hdbt_set_legacy_privacy_policy_url(array &$variables): void {
if (Drupal::moduleHandler()->moduleExists('helfi_eu_cookie_compliance')) {
$privacyUrl = helfi_eu_cookie_compliance_get_privacy_policy_url();

if ($privacyUrl instanceof Url) {
$privacyUrl->setAbsolute();
$variables['#attached']['drupalSettings']['helfi_react_search']['cookie_privacy_url'] = $privacyUrl->toString();
if ($privacyUrl instanceof Url) {
$privacyUrl->setAbsolute();
$variables['#attached']['drupalSettings']['helfi_react_search']['cookie_privacy_url'] = $privacyUrl->toString();
}
}
}
30 changes: 8 additions & 22 deletions src/js/embedded-content-cookie-compliance.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
/**
* @file
* Load embedded content once the user has approved required cookie category.
*
* Depends on EU Cookie Compliance module.
*/
// eslint-disable-next-line func-names
(function ($, Drupal, drupalSettings) {
function loadEmbeddedContent() {
if (
typeof Drupal.eu_cookie_compliance === 'undefined' ||
!drupalSettings.embedded_media_attributes
) {
return;
}

if (
Drupal.eu_cookie_compliance.hasAgreed('preference') &&
Drupal.eu_cookie_compliance.hasAgreed('statistics')
) {
const loadEmbeddedContent = () => {
if (Drupal.cookieConsent.getConsentStatus(['preferences', 'statistics'])) {
// eslint-disable-next-line no-restricted-syntax
for (const [id, attributes] of Object.entries(drupalSettings.embedded_media_attributes)) {
const iframeElement = document.createElement('iframe');
Expand Down Expand Up @@ -68,18 +57,15 @@
.replaceWith(skipLinkBefore, containerElement, skipLinkAfter);
}
}

// Only load the embedded content once.
$(document).off('eu_cookie_compliance.changeStatus', loadEmbeddedContent);
}
}

// Run after choosing cookie settings.
$(document).on('eu_cookie_compliance.changeStatus', loadEmbeddedContent);
};

// Remove noscript element.
$('.embedded-content-cookie-compliance .js-remove').remove();

// Run after page is ready.
$(document).ready(loadEmbeddedContent);
if (Drupal.cookieConsent.initialized()) {
loadEmbeddedContent();
} else {
Drupal.cookieConsent.loadFunction(loadEmbeddedContent);
}
})(jQuery, Drupal, drupalSettings);
20 changes: 8 additions & 12 deletions src/js/matomo.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// eslint-disable-next-line func-names
(function ($, Drupal) {
function loadMatomoAnalytics() {
/**
* If the queryparameter is found, the script will be loaded
/**
* If the queryparameter is found, the script will be loaded
* regardless of cookie consents etc.
*/
const useJSAPI = window.location.search === '?9mt5bfb2bGk=';
Expand Down Expand Up @@ -40,12 +40,8 @@
})();
}

if (!useJSAPI && typeof Drupal.eu_cookie_compliance === 'undefined') {
return;
}

// Load Matomo only if statistics cookies are allowed.
if (!useJSAPI && Drupal.eu_cookie_compliance.hasAgreed('statistics')) {
if (!useJSAPI && Drupal.cookieConsent.getConsentStatus(['statistics'])) {
// Matomo Tag Manager
// eslint-disable-next-line no-multi-assign
const _mtm = (window._mtm = window._mtm || []);
Expand All @@ -63,11 +59,11 @@
}
}

// Load when cookie settings are changed.
$(document).on('eu_cookie_compliance.changeStatus', loadMatomoAnalytics());

// Load on page load.
$(document).ready(loadMatomoAnalytics);
if (Drupal.cookieConsent.initialized()) {
loadMatomoAnalytics();
} else {
Drupal.cookieConsent.loadFunction(loadMatomoAnalytics);
}
})(jQuery, Drupal);

// Clean/refactor this file when the testing phase is done
Expand Down
Loading
Loading