protonsystems / cookie-consent
Reusable, theme-overridable Drupal 11 cookie consent module built on vanilla-cookieconsent, used headlessly.
Package info
gitlab.com/Proton.Systems/drupal/cookie-consent
Type:drupal-module
pkg:composer/protonsystems/cookie-consent
Requires
- php: ^8.3
- drupal/core: ^11
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
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.modulecontains the theme, page, and preprocess hooks.src/Form/contains the admin settings form.templates/contains the banner/modal/badge/gate/embed Twig templates.css/andjs/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.mddocuments 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.