Search by

protonsystems / cookie-consent

proton.systems

Reusable, theme-overridable Drupal 11 cookie consent module built on vanilla-cookieconsent, used headlessly.

Package info

gitlab.com/Proton.Systems/drupal/cookie-consent

Issues

Type:drupal-module

pkg:composer/protonsystems/cookie-consent

Statistics

Installs: 8

Dependents: 0

Suggesters: 0

Stars: 0

v1.0.2 2026-09-01 21:39 UTC

This package is auto-updated.

Last update: 2026-09-02 02:39:40 UTC


README

Reusable, theme-overridable Drupal 11 module for cookie consent — a first-visit banner, a preferences dialog, a persistent reopen badge, and consent-gated iframes/scripts, built on vanilla-cookieconsent 3.1.0 used headlessly (as a consent-state engine only; all rendered UI is Drupal's own Twig/CSS).

Purpose

The module is intended to be reused across Drupal 11 projects by installing it as a Composer package and enabling it in the target site.

Requirements

  • Drupal 11
  • PHP 8.3+

Features

  • Renders a first-visit banner, a native <dialog> preferences modal, and a persistent "reopen settings" badge on every non-admin page automatically
  • Three consent categories: required (always on), marketing, external
  • Gates third-party <iframe> embeds behind consent, with a same-origin/ allowlisted-hosts check before ever loading one
  • Gates <script> tags that draw visible UI, showing a placeholder until their category is accepted
  • All copy, categories, cookie settings, embed allowlist, and policy links are editable via config — no template/PHP changes needed per project
  • Every piece of UI is its own theme hook, independently overridable per-theme

Structure

  • cookie_consent.module contains the theme, page, and preprocess hooks.
  • src/Form/ contains the admin settings form.
  • templates/ contains the banner/modal/badge/gate/embed Twig templates.
  • css/ and js/ contain the default styling and the ported consent behavior, plus the vendored vanilla-cookieconsent library.
  • config/ contains shipped defaults and config schema.
  • docs/module-architecture.md documents how the module is built — the gating mechanism, theme hook contract, and override points — for anyone changing or extending it.

Installation

composer require protonsystems/cookie-consent

Then enable the module in Drupal:

drush en cookie_consent

Configure categories, policy links, the embed allowlist, and all UI text at /admin/config/system/cookie-consent (permission: administer cookie consent), then drush cex to keep that configuration in config/sync.

Theme Integration

No theme changes are required to get a working, styled UI — the module ships its own default CSS and templates render automatically on every non-admin page.

To restyle a piece of UI, copy its template into the theme's templates/ directory (Drupal's standard template discovery picks it up) and disable the module's default CSS via libraries-override in the theme's .info.yml.

To gate a specific embed server-side (e.g. a video field), render #theme => 'cookie_consent_embed' in place of the real iframe from a project-specific hook_preprocess_HOOK().

See docs/module-architecture.md for the full theme hook reference, configuration reference, and customization details.

Notes

The module currently uses Drupal core services directly and is designed to be consumed as a standard Drupal module package.