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 #832

Open
wants to merge 42 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
070f189
UHF-8650: Switch react and share to use hds cookie banner
Arkkimaagi Oct 11, 2024
656197d
UHF-8650: Renamed the cookie policy to cookie settings.
khalima Oct 14, 2024
aca5b0e
UHF-8650: Fixed PHPStan and PHPCS errors from hel_map.
khalima Oct 15, 2024
a457a83
UHF-8650: Added default JSON without any cookies to "site_settings". …
khalima Oct 21, 2024
062b2f7
UHF-8650: Changed the cookie policy page controller to cookie setting…
khalima Oct 21, 2024
c1e4bae
UHF-8650: Converted the cookie banner attachment to a service.
khalima Oct 21, 2024
fdd401a
UHF-8650: Use KernelTestBase instead of cookie banner kernel test base.
khalima Oct 21, 2024
6f2638f
UHF-8650: Added install hooks for the cookie banner module.
khalima Oct 21, 2024
bc37c57
UHF-8650: Define the cookie banner services.
khalima Oct 21, 2024
b90466c
UHF-8650: Added tests to the Cookie settings service.
khalima Oct 21, 2024
1f7252f
UHF-8650: Get the cookie settings page URL via cookie_settings service.
khalima Oct 21, 2024
46037d5
UHF-8650: Removed todo comment.
khalima Oct 21, 2024
01eb14d
UHF-8650: Added a fallback for the helfi_react_search cookie privacy …
khalima Oct 21, 2024
709a400
UHF-8650: Added uninstall hook to remove all obsolete configurations.
khalima Oct 21, 2024
9e84cf8
UHF-8650: Use HDBT cookie banner cookie settings URL if available. Ot…
khalima Oct 21, 2024
a8987cf
UHF-8650: Check if privacy_policy_url exists.
khalima Oct 21, 2024
4518f94
UHF-8650: More consistent todo messages to help the spring-cleaning.
khalima Oct 21, 2024
c0654a2
UHF-8650: Use MediaEntityBundle base class to minimize the duplicated…
khalima Oct 21, 2024
58ac6b2
UHF-8650: Merge branch 'UHF-8650_cookie_banner_activation' of https:/…
khalima Oct 21, 2024
878b262
UHF-8650: Added Drupal.cookieConsent global status handlers.
khalima Oct 22, 2024
bf2246c
UHF-8650: Get consent statuses via the global Drupal.cookieConsent ob…
khalima Oct 22, 2024
9f23507
UHF-8650: Load the cookie banner JS files in HEAD.
khalima Oct 22, 2024
50a5dc1
UHF-8650: Converted the cookie_privacy_url to string.
khalima Oct 22, 2024
0029824
UHF-8650: Fixed the weights for the cookieConsent files and added uni…
khalima Oct 22, 2024
b87aea2
UHF-8650: Use global Drupal.cookieConsent functions to check the cons…
khalima Oct 22, 2024
feaab60
UHF-8650: Fixed the setAcceptedCategories callback.
khalima Oct 22, 2024
9cd727e
UHF-8650: Use global Drupal.cookieConsent functions to check the cons…
khalima Oct 23, 2024
6885ef4
UHF-8650: Merge branch 'UHF-8650' of https://github.com/City-of-Helsi…
khalima Oct 23, 2024
e3b4f99
UHF-8650: Fixed phpcs.
khalima Oct 23, 2024
32bd4e5
UHF-8650: Fixed phpcs.
khalima Oct 23, 2024
cc6b9fe
UHF-8650: Remove the deprecation warning as the logs will get flooded…
khalima Oct 23, 2024
7d83bb5
UHF-8650: Hardcoded the hdbt_cookie_banner module path.
khalima Oct 23, 2024
de9d809
UHF-8650: Remove unused use statement.
khalima Oct 23, 2024
1b3eabc
Testing to see if tests fail because of the uninstall hook.
khalima Oct 24, 2024
9b47978
Revert the uninstall hook
khalima Oct 24, 2024
579e912
UHF-8650: Attempt to fix the typed error with cookies_consent_intro.
khalima Oct 24, 2024
d02f99c
UHF-8650: Revered last commit.
khalima Oct 24, 2024
894a3e5
UHF-8650: Removed helfi_eu_cookie_compliance uninstallation.
khalima Oct 24, 2024
7fed5ba
UHF-8650: Switched the module uninstallation to update hook. This wil…
khalima Oct 24, 2024
fbf65af
UHF-8650: Revered last commit and do the uninstallation in another br…
khalima Oct 24, 2024
c513e8c
UHF-8650: Merge branch 'main' of https://github.com/City-of-Helsinki/…
khalima Oct 24, 2024
6b226da
UHF-8650: Added the cookie consent library version number as a cache …
khalima Oct 24, 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
9 changes: 3 additions & 6 deletions assets/js/chat_leijuke.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,18 @@
console.warn(`No adapter found for ${chatSelection}!`);
}

// @todo UHF-8650: EU Cookie Compliance module will be removed.
// @todo UHF-8650: Convert the following code to support HDS cookie banner.
class EuCookieManager {
cookieCheck(cookieNames) {
let cookiesOk = true;
cookieNames.map((cookieName) => {
if (!Drupal.eu_cookie_compliance.hasAgreedWithCategory(cookieName)) cookiesOk = false;
if (!Drupal.cookieConsent.getConsentStatus([cookieName])) cookiesOk = false;
});
return cookiesOk;
}

cookieSet() {
if (Drupal.eu_cookie_compliance.hasAgreedWithCategory('chat')) return;
if (Drupal.cookieConsent.getConsentStatus(['chat'])) return;

Drupal.eu_cookie_compliance.setAcceptedCategories([ ...Drupal.eu_cookie_compliance.getAcceptedCategories(), 'chat' ]);
Drupal.cookieConsent.setAcceptedCategories(['chat']);
}
}

Expand Down
5 changes: 1 addition & 4 deletions assets/js/clear-localstorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
'use strict';

var clearLocalStorage = function () {
if (typeof Drupal.eu_cookie_compliance === 'undefined') {
return;
}

if (!Drupal.eu_cookie_compliance.hasAgreed('statistics')) {
if (!Drupal.cookieConsent.getConsentStatus(['statistics'])) {
var requireStatistics = [
'rnsbid',
'rnsbid_ts',
Expand Down
14 changes: 5 additions & 9 deletions assets/js/reactAndShareSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
'use strict';

var loadReactAndShare = function () {
// @todo UHF-8650: EU Cookie Compliance module will be removed.
// @todo UHF-8650: Convert the following code to support HDS cookie banner.
if (Drupal.eu_cookie_compliance.hasAgreed('statistics')) {
if (Drupal.cookieConsent.getConsentStatus(['statistics'])) {
window.rnsData = {
apiKey: drupalSettings.reactAndShareApiKey,
disableFa: true,
Expand Down Expand Up @@ -32,11 +30,9 @@
loadReactAndShare = function () {};
};

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

// Run after page is ready.
$(document).ready(function () {
if (Drupal.cookieConsent.initialized()) {
loadReactAndShare();
});
} else {
Drupal.cookieConsent.loadFunction(loadReactAndShare);
}
})(jQuery, Drupal);
9 changes: 4 additions & 5 deletions assets/js/telia_ace.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@
};
}

// @todo UHF-8650: EU Cookie Compliance module will be removed.
// @todo UHF-8650: Convert the following code to support HDS cookie banner.
// eslint-disable-next-line class-methods-use-this
cookieCheck() {
return Drupal.eu_cookie_compliance.hasAgreedWithCategory('chat');
return Drupal.cookieConsent.getConsentStatus(['chat']);
}

// eslint-disable-next-line class-methods-use-this
cookieSet() {
if (Drupal.eu_cookie_compliance.hasAgreedWithCategory('chat')) return;
Drupal.eu_cookie_compliance.setAcceptedCategories([ ...Drupal.eu_cookie_compliance.getAcceptedCategories(), 'chat' ]);
if (Drupal.cookieConsent.getConsentStatus(['chat'])) return;

Drupal.cookieConsent.setAcceptedCategories(['chat']);
}

init() {
Expand Down
8 changes: 3 additions & 5 deletions assets/js/user_consent_functions.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
(function (Drupal) {
'use strict';

// @todo UHF-8650: EU Cookie Compliance module will be removed.
// @todo UHF-8650: Convert the following code to support HDS cookie banner.
window.chat_user_consent = {
retrieveUserConsent: () => (Drupal.eu_cookie_compliance.hasAgreedWithCategory('chat')),
retrieveUserConsent: () => (Drupal.cookieConsent.getConsentStatus(['chat'])),
confirmUserConsent: () => {
if (Drupal.eu_cookie_compliance.hasAgreedWithCategory('chat')) return;
Drupal.eu_cookie_compliance.setAcceptedCategories([ ...Drupal.eu_cookie_compliance.getAcceptedCategories(), 'chat' ]);
if (Drupal.cookieConsent.getConsentStatus(['chat'])) return;
Drupal.cookieConsent.setAcceptedCategories(['chat']);
}
};

Expand Down
10 changes: 8 additions & 2 deletions helfi_platform_config.module
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function helfi_platform_config_page_attachments_alter(array &$attachments): void
*/
function helfi_platform_config_theme() : array {
return [
// @todo Deprecated. Remove when the EU cookie compliance module is removed.
// @todo UHF-10862 Remove cookie_consent_intro once the HDBT cookie banner module is in use.
'cookie_consent_intro' => [
'variables' => [
'title' => NULL,
Expand Down Expand Up @@ -403,7 +403,13 @@ function helfi_platform_config_system_breadcrumb_alter(
* Implements hook_preprocess_HOOK().
*/
function helfi_platform_config_preprocess_react_and_share(&$variables) : void {
if (Drupal::moduleHandler()->moduleExists('helfi_eu_cookie_compliance')) {
if (Drupal::moduleHandler()->moduleExists('hdbt_cookie_banner')) {
/** @var \Drupal\hdbt_cookie_banner\Services\CookieSettings $cookie_settings */
$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();
}
}
Expand Down
27 changes: 26 additions & 1 deletion modules/hdbt_cookie_banner/assets/js/hdbt-cookie-banner.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
(function (Drupal, drupalSettings) {
'use strict';

((Drupal, drupalSettings) => {

// Global cookie consent status object.
Drupal.cookieConsent = {
initialized: () => {
return window && window.hds.cookieConsent;
},
loadFunction: (loadFunction) => {
if (typeof loadFunction === 'function') {
document.addEventListener('hds_cookieConsent_ready', loadFunction);
}
},
getConsentStatus: (categories) => {
return window &&
window.hds.cookieConsent &&
window.hds.cookieConsent.getConsentStatus(categories);
},
setAcceptedCategories: (categories) => {
if (Drupal.cookieConsent.initialized()) {
window.hds.cookieConsent.setGroupsStatusToAccepted(categories);
}
},
};

Drupal.behaviors.hdbt_cookie_banner = {
attach: function () {
if (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
langcode: en
site_settings: ''
site_settings: '{"languages":[{"code":"fi","name":"Finnish","direction":"ltr"},{"code":"sv","name":"Swedish","direction":"ltr"},{"code":"en","name":"English","direction":"ltr"}],"siteName":"Hel.fi","cookieName":"helfi-cookie-consents","monitorInterval":500,"fallbackLanguage":"en","requiredGroups":[{"groupId":"essential","title":{"fi":"Välttämättömät toiminnalliset evästeet","sv":"Nödvändiga funktionella cookies","en":"Essential cookies"},"description":{"fi":"Välttämättömät evästeet auttavat tekemään verkkosivustosta käyttökelpoisen sallimalla perustoimintoja, kuten sivulla siirtymisen ja sivuston suojattujen alueiden käytön. Verkkosivusto ei toimi kunnolla ilman näitä evästeitä eikä niihin tarvita suostumusta.","sv":"Nödvändiga cookies hjälper till att göra webbplatsen användbar genom att tillåta grundläggande funktioner som att navigera på sidan och använda de skyddade områdena på webbplatsen. Webbplatsen fungerar inte korrekt utan dessa cookies och kräver inte samtycke.","en":"Essential cookies help to make the website usable by allowing basic functions, navigating the page and using the protected areas of the site. The website will not work properly without these cookies and their consent is not required."},"cookies":[{"name":"helfi-cookie-consents","host":"www.hel.fi","type":1,"description":{"fi":"Sivusto käyttää tätä evästettä tietojen tallentamiseen siitä, ovatko kävijät antaneet hyväksyntänsä tai kieltäytyneet evästeiden käytöstä.","sv":"Cookie möjliggör hantering av cookies på webbplatsen.","en":"Used by www.hel.fi Drupal to store information about whether visitors have given or declined the use of cookie categories used on the www.hel.fi site."},"expiration":{"fi":"100 päivää","sv":"100 dagar","en":"100 days"}}]}],"optionalGroups":[],"translations":{"bannerAriaLabel":{"fi":"Evästeasetukset","sv":"Inställningar för kakor","en":"Cookie settings"},"heading":{"fi":"${siteName} käyttää evästeitä","sv":"${siteName} använder kakor","en":"${siteName} uses cookies"},"description":{"fi":"Tämä sivusto käyttää välttämättömiä evästeitä sivun perustoimintojen ja suorituskyvyn varmistamiseksi. Lisäksi käytämme kohdennusevästeitä käyttäjäkokemuksen parantamiseksi, analytiikkaan ja yksilöidyn sisällön näyttämiseen.","sv":"Denna webbplats använder obligatoriska kakor för att säkerställa de grundläggande funktionerna och prestandan. Dessutom använder vi inriktningskakor för bättre användarupplevelse, analytik och individualiserat innehåll.","en":"This website uses required cookies to ensure the basic functionality and performance. In addition, we use targeting cookies to improve the user experience, perform analytics and display personalised content."},"showDetails":{"fi":"Näytä yksityiskohdat","sv":"Visa detaljer","en":"Show details"},"hideDetails":{"fi":"Piilota yksityiskohdat","sv":"Stänga detaljer","en":"Hide details"},"form_heading":{"fi":"Tietoa sivustolla käytetyistä evästeistä","sv":"Information om kakor som används på webbplatsen","en":"About the cookies used on the website"},"form_text":{"fi":"Sivustolla käytetyt evästeet on luokiteltu käyttötarkoituksen mukaan. Alla voit lukea eri luokista ja sallia tai kieltää evästeiden käytön.","sv":"Kakorna som används på webbplatsen har klassificerats enligt användningsändamål. Du kan läsa om de olika klasserna och acceptera eller förbjuda användningen av kakor.","en":"The cookies used on the website have been classified according to their intended use. Below, you can read about the various categories and accept or reject the use of cookies."},"highlightedGroup":{"fi":"Sinun on hyväksyttävä tämä kategoria, jotta voit näyttää valitsemasi sisällön.","sv":"Du måste acceptera den här kategorin för att visa innehållet du har valt.","en":"You need to accept this category to display the content you have selected."},"highlightedGroupAria":{"fi":"Hyvä tietää kategorialle: ${title}","sv":"Bra att veta för kategorin: ${title}","en":"Good to know for category: ${title}"},"showCookieSettings":{"fi":"Näytä evästeasetukset","sv":"Visa kakinställningarna","en":"Show cookie settings"},"hideCookieSettings":{"fi":"Piilota evästeasetukset","sv":"Stänga kakinställningarna","en":"Hide cookie settings"},"acceptedAt":{"fi":"Olet hyväksynyt tämän kategorian: ${date} klo ${time}.","sv":"Du har accepterat denna kategori: ${date} kl. ${time}.","en":"You have accepted this category: ${date} at ${time}."},"tableHeadingsName":{"fi":"Nimi","sv":"Namn","en":"Name"},"tableHeadingsHostName":{"fi":"Evästeen asettaja","sv":"Den som lagrat kakan","en":"Cookie set by"},"tableHeadingsDescription":{"fi":"Käyttötarkoitus","sv":"Användning","en":"Purpose of use"},"tableHeadingsExpiration":{"fi":"Voimassaoloaika","sv":"Giltighetstid","en":"Period of validity"},"tableHeadingsType":{"fi":"Tyyppi","sv":"Typ","en":"Type"},"approveAllConsents":{"fi":"Hyväksy kaikki evästeet","sv":"Acceptera alla kakor","en":"Accept all cookies"},"approveRequiredAndSelectedConsents":{"fi":"Hyväksy valitut evästeet","sv":"Acceptera valda kakor","en":"Accept selected cookies"},"approveOnlyRequiredConsents":{"fi":"Hyväksy vain välttämättömät evästeet","sv":"Acceptera endast nödvändiga","en":"Accept required cookies only"},"settingsSaved":{"fi":"Asetukset tallennettu!","sv":"Inställningar sparade!","en":"Settings saved!"},"notificationAriaLabel":{"fi":"Ilmoitus","sv":"Meddelande","en":"Annoucement"},"type_1":{"fi":"Eväste","sv":"Kakan","en":"Cookie"},"type_2":"localStorage","type_3":"sessionStorage","type_4":"IndexedDB","type_5":"Cache Storage"}}'
cookie_information:
title: 'Cookie information'
content: "A cookie is a small-scale data storage program that a computer browser installs on a user's computer hard drive. Whenever the user's browser retrieves the site from the City of Helsinki's servers, the message is sent back to the user's computer. Javascript and server logs are used to record, for example, the number of users, country of use, usage time and browser used, as well as the content that the visitor has visited. The cookie does not damage the drive.\r\n\r\nCookies are used to speed up, analyze and develop the website and to target content to each user."
49 changes: 49 additions & 0 deletions modules/hdbt_cookie_banner/hdbt_cookie_banner.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/**
* @file
* Contains installation tasks for hdbt_cookie_banner module.
*/

declare(strict_types=1);

/**
* Grants required permissions.
*/
function hdbt_cookie_banner_grant_permissions() : void {
$permissions = [
'admin' => [
'administer hdbt_cookie_banner',
],
];
helfi_platform_config_grant_permissions($permissions);
}

/**
* Implements hook_install().
*/
function hdbt_cookie_banner_install($is_syncing) : void {
// Do not perform following steps if the module is being installed as part
// of a configuration import.
if ($is_syncing) {
return;
}

// Uninstall the EU Cookie compliance and Helfi EU Cookie compliance
// modules if they are installed.
$module_handler = \Drupal::moduleHandler();
$module_installer = \Drupal::service('module_installer');

if (
$module_handler->moduleExists('eu_cookie_compliance') ||
$module_handler->moduleExists('helfi_eu_cookie_compliance')
) {
$module_installer->uninstall([
'eu_cookie_compliance',
'helfi_eu_cookie_compliance',
]);
}

// Grant required permissions.
hdbt_cookie_banner_grant_permissions();
}
7 changes: 5 additions & 2 deletions modules/hdbt_cookie_banner/hdbt_cookie_banner.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,16 @@ cookie_banner_admin_ui:

hdbt_cookie_banner:
version: 1.0.0
header: true
js:
assets/js/hdbt-cookie-banner.js: {}
# The weight needs to be as low as drupal.init.js, which is -17.
assets/js/hdbt-cookie-banner.js: { weight: -16 }
dependencies:
- core/drupal
- core/drupalSettings

hds_cookie_consent:
version: 1.0.0
header: true
js:
assets/js/hds-cookie-consent.min.js: { minified: true, preprocess: false }
assets/js/hds-cookie-consent.min.js: { weight: -17, minified: true, preprocess: false }
99 changes: 27 additions & 72 deletions modules/hdbt_cookie_banner/hdbt_cookie_banner.module
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ declare(strict_types=1);
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Url;
use Drupal\hdbt_cookie_banner\Form\HdbtCookieBannerForm;
use Drupal\helfi_api_base\Environment\EnvironmentEnum;
use Drupal\helfi_api_base\Environment\EnvironmentResolverInterface;
use Drupal\helfi_api_base\Environment\Project;

/**
* Implements hook_config_ignore_settings_alter().
Expand All @@ -26,7 +23,7 @@ function hdbt_cookie_banner_config_ignore_settings_alter(array &$settings): void
*/
function hdbt_cookie_banner_theme() : array {
return [
'cookie_policy' => [
'cookie_settings_page' => [
'variables' => [
'title' => NULL,
'content' => NULL,
Expand All @@ -43,18 +40,21 @@ function hdbt_cookie_banner_page_attachments(array &$attachments) : void {
$langcode = \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();
$attachments['#cache']['tags'] = array_merge($attachments['#cache']['tags'] ?? [], $config->getCacheTags());

/** @var \Drupal\hdbt_cookie_banner\Services\CookieSettings $cookie_settings_service */
$cookie_settings_service = \Drupal::service('hdbt_cookie_banner.cookie_settings');

// By default, we use the hel.fi etusivu instance HDS cookie consent JS file.
if (empty($config->get('use_custom_settings'))) {
_hdbt_cookie_banner_attach_hds_cookie_consent($attachments['#attached']);
$cookie_settings_service->injectBannerJavaScript($attachments);
}
// We can also use the current instance HDS cookie consent JS file.
elseif (empty($config->get('use_internal_hds_cookie_js'))) {
$attachments['#attached']['library'][] = 'hdbt_cookie_banner/hds_cookie_consent';
}
// Or the custom HDS cookie consent JS file can be used.
else {
_hdbt_cookie_banner_attach_hds_cookie_consent(
$attachments['#attached'],
$cookie_settings_service->injectBannerJavaScript(
$attachments,
$config->get('hds_cookie_js_override')
);
}
Expand All @@ -64,77 +64,32 @@ function hdbt_cookie_banner_page_attachments(array &$attachments) : void {

// Attach HDBT cookie banner settings.
$attachments['#attached']['drupalSettings']['hdbt_cookie_banner'] = [
'apiUrl' => _hdbt_cookie_banner_get_api_url(),
'apiUrl' => $cookie_settings_service->getCookieBannerApiUrl(),
'langcode' => $langcode,
'theme' => 'black',
'settingsPageSelector' => '.cookie-policy-settings',
'settingsPageSelector' => '.cookie-settings',
'settingsPageUrl' => $cookie_settings_service->getCookieSettingsPageUrl()?->setAbsolute()?->toString(),
];
}

/**
* Gets HDBT cookie banner api url.
*/
function _hdbt_cookie_banner_get_api_url(): string {
$config = \Drupal::configFactory()->get(HdbtCookieBannerForm::SETTINGS);
$language = \Drupal::languageManager()->getDefaultLanguage();

// Default to Etusivu API URL.
if (
empty($config->get('site_settings')) ||
!$config->get('use_custom_settings')
) {
/** @var \Drupal\helfi_api_base\Environment\EnvironmentResolverInterface $resolver */
$resolver = \Drupal::service(EnvironmentResolverInterface::class);
try {
$environment = $resolver
->getEnvironment(Project::ETUSIVU, $resolver->getActiveEnvironmentName());

return vsprintf("%s/api/cookie-banner", [
$environment->getUrl($language->getId()),
]);
}
catch (InvalidArgumentException) {
}
}

return Url::fromRoute('hdbt_cookie_banner.site_settings', options: [
'language' => $language,
])->toString();
// Fallback for the old variable used in HDBT theme react search JS.
// @todo UHF-10862 Remove once the HDBT cookie banner module is in use.
$attachments['#attached']['drupalSettings']['helfi_react_search'] = [
'cookie_privacy_url' => $cookie_settings_service->getCookieSettingsPageUrl()?->setAbsolute()?->toString(),
];
}

/**
* Gets HDS cookie consent JavaScript file URL.
* Helper function to get the privacy policy link URL.
*
* @todo UHF-10862 Remove once deprecations have been fixed.
*
* @return \Drupal\Core\Url|string
* Returns the cookie settings page URL or empty string.
*/
function _hdbt_cookie_banner_attach_hds_cookie_consent(&$attached, ?string $library = NULL): void {
// Load HDS cookie consent JavaScript file from Etusivu instance.
if (!$library) {
$resolver = \Drupal::service('helfi_api_base.environment_resolver');
$module_path = \Drupal::service('extension.list.module')->getPath('hdbt_cookie_banner');

// Get active Etusivu environment.
try {
$environment = $resolver->getEnvironment(Project::ETUSIVU, $resolver->getActiveEnvironmentName());
}
catch (\InvalidArgumentException) {
$environment = $resolver->getEnvironment(Project::ETUSIVU, EnvironmentEnum::Prod->value);
}

// Construct the URL to the HDS cookie consent JS file.
$library = vsprintf("%s/etusivu-assets/%s/assets/js/hds-cookie-consent.min.js", [
$environment->getBaseUrl(),
$module_path,
]);
}

// Attach the HDS cookie consent JS file to HTML head.
$attached['html_head'][] = [
[
'#tag' => 'script',
'#attributes' => [
'src' => $library,
'type' => 'text/javascript',
],
],
'external_script',
];
// phpcs:ignore Drupal.Commenting.FunctionComment.Missing, Drupal.NamingConventions.ValidFunctionName.InvalidPrefix
function helfi_eu_cookie_compliance_get_privacy_policy_url(): Url|string {
// Use the HDBT cookie banner cookie settings service to retrieve the
// cookie settings page URL.
$cookie_settings = Drupal::service('hdbt_cookie_banner.cookie_settings');
return $cookie_settings->getCookieSettingsPageUrl();
}
Loading
Loading