Skip to main content
drupalreleases
Release: Cms 2.2.3 — Update released for Drupal core (2.2.3)! Release: Easy Breadcrumb 2.0.11 — Minor update available for module easy_breadcrumb (2.0.11). Release: Bootstrap 8.x-3.42 — Minor update available for theme bootstrap (8.x-3.42). Release: Editoria11y Accessibility Checker 3.0.10 — Minor update available for module editoria11y (3.0.10). Release: Editoria11y Accessibility Checker 2.2.24 — Minor update available for module editoria11y (2.2.24). Release: Leaflet 10.4.13 — Minor update available for module leaflet (10.4.13). Release: Flag 5.1.1 — Minor update available for module flag (5.1.1). Release: MCP Sentinel 2.33.0 — Minor update available for module mcp_sentinel (2.33.0). Module Revived: Bootstrap 8.x-3.41 — Theme bootstrap updated after 6 months of inactivity (8.x-3.41). Security Coverage: Component Library — Module component_library now has official Drupal security advisory coverage.

This module helps integrate cookie consent solutions with automatic script blocking by allowing you to categorize libraries and scripts based on their purpose. It provides a user interface to manage these categorizations and works with external cookie consent services like CookieBot. Note that this module will not work with JavaScript aggregation.

Cookie consent application, like CookiePro or CookieBot, have automatic cookie blocking which makes it very simple to integrate a compliant cookie policy. The auto-blockers work by preventing scripts from running. This is not compatible with Drupal out-the-box as many scripts are required.

Usually these blockers allow tags to be added to the scripts to flag their purpose. This module provides a UI to flag any detected libraries from yml, etc, and additionally any script attachments added in other module's hook_page_attachments_alter().

Cookie application support is provided by plugins. This module comes with only one plugin - CookieBot, because that happens to be the service we use.

How to use this module

Once enabled, a menu entry in the Configuration / System menu will appear with a couple of configuration pages. One is to choose the cookie plugin, and the other is to categorise your site's scripts and libraries.

Aggregation

PLEASE NOTE - this WILL NOT work with JS / script aggregation. This is because Drupal will not aggregate scripts according to type. If anyone has time to tackle that issue here then please provide a patch and we can include that functionality.

Developer notes

Feel free to submit any other cookie provider plugins you think would be useful, e.g. CookiePro, etc. It's super easy and only needs a few lines of code per plugin. Take a look at the included CookieBot plugin for an example.

<?php

namespace Drupal\cookie_blocking_libraries\Plugin\CookieBlockingLibrariesImplementation;

use Drupal\cookie_blocking_libraries\CookieImplementationPluginBase;

/**
 * Plugin implementation of the cookie_blocking_libraries_implementation.
 *
 * @CookieBlockingLibrariesImplementation(
 *   id = "cookie_bot",
 *   label = @Translation("Cookie Bot"),
 *   description = @Translation("Cookie Bot.")
 * )
 */
class CookieBot extends CookieImplementationPluginBase {

  /**
   * {@inheritDoc}
   */
  public function getCategories() : array {
    return parent::getCategories() + [
      'preferences' => $this->t('Preferences'),
      'statistics' => $this->t('Statistics'),
      'marketing' => $this->t('Marketing'),
      'ignore' => $this->t('Ignore'),
    ];
  }

  /**
   * {@inheritDoc}
   */
  public function getDefaultCategory() : string {
    return 'ignore';
  }

  /**
   * {@inheritDoc}
   */
  public function alterLibrary(array &$library_js, $extension, $type) : void {
    $library_js['attributes']['data-cookieconsent'] = $type;
  }

  /**
   * {@inheritDoc}
   */
  public function alterAttachment(array &$html, $extension, $type) : void {
    $html['#attributes']['data-cookieconsent'] = $type;
  }

}

Any maintainers for cookie control modules can include the plugin in their modules if preferred.

The plugin only has to implement four methods

  • getCategories() Return an array list of categorisations, e.g. Marketing, Statistics, etc.
  • getDefaultCategory() Return a string of the default category, e.g. ignore
  • alterLibrary() Change the library definition, e.g. add an attribute.
  • alterAttachment() Change the attached script tag, e.g. add an attribute.

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
2
Tracked since
Mar 2024
Latest release
1 month ago
Releases (12 mo)
1 ▲ from 0
Maintenance
Active

Releases

Version Type Core Release date
1.0.1 Stable 10–11 Aug 21, 2026
1.0.x-dev Dev 10–11 Mar 20, 2024