Klaro Cookie Consent: Technical Details
Technical details of Klaro Cookie Consent for Sylius 2 - architecture, plugin structure, tables, admin Twig Hooks and extensibility.
Klaro Cookie Consent: Technical Details
This documentation always describes the latest published version.
Architecture
graph LR
A["Admin CRUD: ConsentService"] --> C["KlaroConfigBuilder"]
B["Admin CRUD: ChannelConfiguration"] --> C
C --> D["window.klaroConfig (JSON)"]
D --> E["klaro.js (vendored)"]
C --> F["Google Consent Mode bridge"]
F --> G["gtag consent update"]
All domain logic lives in KlaroConfigBuilder and the two repositories, independent of the rendering layer. The admin CRUD interfaces (ConsentService, ChannelConfiguration) are purely back-office features; the storefront banner only reads the result.
Plugin structure
src/Entity ConsentService(+Translation), ChannelConfiguration, enums
src/Repository Doctrine repositories behind interfaces
src/Factory Translatable factory for an admin-created ConsentService
src/Form/Type Admin form types
src/Klaro KlaroConfigBuilder (window.klaroConfig), PrivacyPolicyLinkResolver, NoticeExemptPages
src/Twig Storefront Twig functions + asset URLs
src/Menu Shared "MMKreativ Plugins" admin sidebar group
src/Command Setup command
src/Migrations Three Doctrine migrations
templates/shop Twig Hook templates (stylesheets, scripts, footer link)
templates/admin Title blocks of the admin pages
Resources/public Vendored klaro.js/klaro.css + KLARO-LICENSE.txt
Tables
graph TD
A["mmd_sylius_klaro_consent_service"] --> B["mmd_sylius_klaro_consent_service_translation"]
A --> C["mmd_sylius_klaro_consent_service_channel (pivot)"]
D["sylius_channel"] --> C
D --> E["mmd_sylius_klaro_channel_configuration"]
Four plugin-owned tables, created across three migrations: the main services table, its translation table, the many-to-many channel assignment, and a table holding exactly one configuration row per channel.
Admin Twig Hooks
In addition to the three storefront hooks (see Storefront Integration), the plugin hooks into its own admin grid pages with four hooks, to set titles and navigation buttons between the two grids:
| Hook | Effect |
|---|---|
sylius_admin.klaro_channel_configuration.index.content.header.title_block |
Title of the channel configurations page |
sylius_admin.klaro_consent_service.index.content.header.title_block |
Title of the consent services page |
sylius_admin.klaro_channel_configuration.index.content.header.title_block.actions |
Button to "Consent services" |
sylius_admin.klaro_consent_service.index.content.header.title_block.actions |
Button to "Klaro settings" |
Extensibility
The plugin deliberately ships no events or service tags of its own for third parties. What can be adapted:
- Decorate
KlaroConfigBuilderInterface: the service is registered as an interface with an alias, so it is replaceable through the usual Symfony decorator mechanism if you want to change the generatedklaroConfigstructure. - Override resource classes:
ConsentService,ChannelConfigurationand their repositories are registered as regular Sylius resources and can be replaced with the usual Sylius override mechanism, like any other Sylius resource.
Beyond that there are no plugin-specific extension points: no PSR-14 events, no custom service tags.
Quality assurance
Behat covers creating/editing/deleting services, configuring a channel, and the storefront rendering (banner, klaro.js, footer link, Google Consent Mode script) for enabled, disabled and unconfigured channels, across three suites, over Mink's Symfony session without Chrome. PHPStan runs at level max, the code style follows sylius-labs/coding-standard.