The HDBT cookie banner module brings support for the Helsinki Design System (HDS) cookie banner.
The HDBT cookie banner is included in the following versions of the Helfi packages:
Module | Minimum Version | Description |
---|---|---|
helfi_platform_config | ^4.6.23 | Includes the HDBT cookie banner module. |
hdbt | ^6.7.22 | Includes updates to component templates, styles, and JavaScript. |
hdbt_admin | ^3.2.7 | Supports the cookie banner in the admin theme. |
Ensure your local environment is up and running on the latest development branch.
- Update the Helfi packages to the latest versions:
composer update drupal/helfi_platform_config drupal/hdbt drupal/hdbt_admin -W
- Uninstall the EU Cookie Compliance module. This will also uninstall the Helfi EU Cookie Compliance module:
drush pmu -y eu_cookie_compliance
- Install the HDBT cookie banner module:
drush en -y hdbt_cookie_banner
- Export your configuration:
drush cex -y
- Review the updated configurations and commit the changes to your repository.
By default, the cookie banner JS library is attached to a HTML tag with footer
class. If you don't have an HTML tag with footer
class in your DOM, I.e. in page.html.twig
, you'll need to add it. Here is an example: https://github.com/City-of-Helsinki/drupal-hdbt/blob/main/templates/layout/page.html.twig#L209
- Log in to Drupal and navigate to
/admin/structure/hdbt-cookie-banner
. - The
Site settings
text area contains the cookie information in JSON format. This data is saved as a configuration object but is not saved toconf/cmi/
, so you need to configure the JSON manually:- Enable
Use instance-specific cookie settings
- Scroll down to the
Site settings
textarea. - Copy the contents from siteSettingsTemplate.json to the text area. The template provides basic cookie information for Helfi Drupal sites.
- Go through each variable in the cookie information and adjust the values to match your needs. Some values are labeled such as
Change me
,change-me
orchange-me.hel.fi
which you need to modify to avoid cookie conflicts.- Please note, that the
Cookie name
field needs to be the same as the Name of the cookie in Essential Groups - Item 1. This is where the cookie banner settings are stored.
- Please note, that the
- Save the changes
- Enable
- Verify that the cookie banner is functioning as expected.
- You can use the browser developer tools console to see if there are any errors or missing cookies. The messages would be self-explanatory, like:
Cookie consent: found unapproved localStorage(s): 'storage.name'
orError: Cookie consent: The spacerParentSelector element '.footer' was not found'
. - Fix the possible errors, adjust the cookie settings as needed and save the changes. Verify that the updates are applied correctly.
- You can use the browser developer tools console to see if there are any errors or missing cookies. The messages would be self-explanatory, like:
- Check if any JavaScript in your Drupal uses the
Drupal.eu_cookie_compliance.hasAgreed()
function. If so, replace the function call withDrupal.cookieConsent.getConsentStatus()
. It will work the same way as the EU Cookie Compliance hasAgreed function. - When deploying to test, staging, or production environments, manually copy the
Site settings
JSON to the textarea.
Helfi platform config 4.x brings support to Drupal 10.
Get your local environment up and running.
- Update the Drupal packages and helfi packages to latest versions.
composer require drupal/core:^10.1 drupal/core-composer-scaffold:^10.1 drush/drush:^12 drupal/helfi_platform_config:^4.0 drupal/hdbt:^6.0 drupal/hdbt_admin:^3.0 -W
- If the installation fails due to conflicting problems, like:
drupal/raven is locked to version 4.0.16 and an update of this package was not requested.
, then include thedrupal/raven:^4.0
to the requirements, like so:composer require drupal/core:^10.1 drupal/core-composer-scaffold:^10.1 drush/drush:^12 drupal/helfi_platform_config:^4.0 drupal/hdbt:^6.0 drupal/hdbt_admin:^3.0 drupal/raven:^4.0 -W
- Update the core-dev package separately, as it's dev-dependency:
composer require drupal/core-dev:^10.1 --dev -W
- After the packages have been installed, run the database updates
make drush-updb
ordrush updb
- Export your configuration
make drush-cex
ordrush cex -y
- Go through the changed configurations and manually discard any unwanted changes.
There shouldn't be any problems after deployment, but if any occurs, cache clear and running an extra drush deploy command should fix the problems.
drush cr; drush deploy
- Update the module to latest 2.x version:
composer update drupal/helfi_platform_config
- Run database updates (
drush updb
) - Export your configuration (
drush config:export
)
- Remove
helfi_media_map
module:composer remove drupal/helfi_media_map
(this will be included in 3.x platform config module) - Update the module to 3.x version:
composer require drupal/helfi_platform_config:^3.0 drupal/hdbt:^5.0 drupal/hdbt_admin:^2.0 drush/drush:^11 -W
- Run
drush helfi:platform-config:update-config
. This will override all configuration in your config export folder. Make sure to review and discard any unwanted changes before the next step - Run
drush config:import
to import overridden configuration. The import command will most likely fail to something like:
In ConfigImportCommands.php line 324:
The import failed due to the following reasons:
Configuration <em class="placeholder">block.block.announcements</em> depends on the <em class="placeholder">helfi_announcements</em> module that will not be installed after import.
Configuration <em class="placeholder">block.block.hdbt_subtheme_announcements</em> depends on the <em class="placeholder">helfi_announcements</em> module that will not be installed after import.
- This happens because we've renamed some modules providing the said configuration.
- See
\Drupal\helfi_platform_config\Commands\MajorUpdateCommands::getModuleMap()
for a key value list of replacement module names. For examplehelfi_announcements
is now calledhelfi_node_announcements
. - You can search and replace these with
sed
, for example:find conf/cmi -name '*.yml' -exec sed -i 's/helfi_announcements/helfi_node_announcement/g' {} +
. Repeat this steps until you've replaced all conflicting modules
- See
- If the
drush config:import
command fails to something like:
In ConfigImportCommands.php line 324:
The import failed due to the following reasons:
Unexpected error during import with operation delete for core.entity_form_display.media.soundcloud.default: The "soundcloud" plugin does not exist. Valid plugin IDs for Drupal\media\MediaSourceManager are: hel_map, video_file, oembed:vid
eo, file, image, audio_file, helfi_chart
- Run
drush cache:clear
and rerundrush config:import
command until it succeeds - Run
drush config:export
to export changed configuration - Review and manually discard any unwanted changes
- Run
drush helfi:platform-config:update-database
and re-import configurationdrush config:import
- If the configuration import fails, run
drush cache:rebuild
anddrush config:import
until the import is succesful
- Install the site with existing configuration by running either
make new
ormake fresh
. - When the site is up and running, run
composer require drupal/helfi_platform_config:^2.0
to retrieve the new version of HELfi Platform config. - Run updates and export the configurations by running
make drush-updb drush-cr drush-cex
. - Go through configuration changes from
/conf/cmi/
and revert/modify any changes what will override customised configurations. - Commit the changes to your repository.