Drupal is a registered trademark of Dries Buytaert
Release: Leaflet 10.4.11 Minor update available for module leaflet (10.4.11). Release: Session Inspector 1.0.8 Minor update available for module session_inspector (1.0.8). Release: Migrate QA 2.0.4 Minor update available for module migrate_qa (2.0.4). Release: CKEditor Description List 3.0.0 Major update available for module ckeditor_descriptionlist (3.0.0). Release: FlowDrop 2.4.0 Minor update available for module flowdrop (2.4.0). Release: JWT Token Refresh 1.0.4 Minor update available for module jwt_token_refresh (1.0.4). Release: ConReg 1.0.0-beta1 First beta version released for module conreg (1.0.0-beta1). Release: AI Image Studio 1.0.0-beta8 New beta version released for module ai_image_studio (1.0.0-beta8). Usage Milestone: Statistics Counter Module statistics_counter crossed 1,000 active installs. Module Revived: Decoupled Router 2.0.7 Module decoupled_router updated after 11 months of inactivity (2.0.7).

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.

Activity

Tracked releases
1
Tracked since
Aug 2026
Latest release
2 days ago
Releases (12 mo)
1 ▲ from 0
Maintenance
Active

Releases

Version Type Release date
1.0.1 Stable Aug 21, 2026