hofff/contao-consent-bridge
Composer 安装命令:
composer require hofff/contao-consent-bridge
包简介
Bridge between consent tools and third party extensions for Contao
README 文档
README
This extension provides a bridge for integrating consent tools into Contao.
It's designed for consent tools which handles consent management on the client side but may require modified html output.
Requirements
- Contao
^4.9 - PHP
^7.1 || ^8.0
Installation
You can install hofff/contao-consent-bridge using Composer/Contao Manager.
Changelog
See changelog
Features
- Provides activation for consent tools in root page
- Assign required consent ids for content elements and adjust output to fullfill requirements of consent tool
- Assign required consent ids for frontend modules and adjust output to fullfill requirements of consent tool
- Provides interface so that rendering for specific frontend templates can be adjusted to fullfill requirements of consent tools
- Built in support to google webfonts defined in the page layout
- Provides plugin infrastructure for extensions so that they are supported
- Provides interface for consent tools
Integration
As extension developer
If you provide an extension with custom content elements or frontend modules which might require consent to be rendered
you can register a plugin which provides extra information. You need to tag it as hofff_contao_consent_bridge.plugin.
namespace Your\Bundle; use Hofff\Contao\Consent\Bridge\Bridge; use Hofff\Contao\Consent\Bridge\Bridge\Plugin; use Hofff\Contao\Consent\Bridge\Render\RenderInformation; class MyPlugin implements \Hofff\Contao\Consent\Bridge\Plugin { public function load(Bridge $bridge): void { $bridge->supportFrontendModule('custom_1', RenderInformation::autoRenderWithoutPlaceholder()); $bridge->supportFrontendModule('custom_2', RenderInformation::autoRenderWithPlaceholder('custom_placeholder_template')); $bridge->supportFrontendModule('custom_3', RenderInformation::customRender()); $bridge->supportContentElement('custom_1', RenderInformation::autoRenderWithoutPlaceholder()); $bridge->supportContentElement('custom_2', RenderInformation::autoRenderWithPlaceholder('custom_placeholder_template')); $bridge->supportContentElement('custom_3', RenderInformation::customRender()); } }
Then there will be a new legend where you can assign a consent id to your configuration, and the rendering of the HTML output will automatically adjust depending on the requirements of the consent tool.
As consent tool developer
As consent tool developer you need to implement the interface Hofff\Contao\Consent\Bridge\ConsentTool and tag it
as hofff_contao_consent_bridge.consent_tool in the dependency injection container. Use the
\Hofff\Contao\Consent\Bridge\WithGenericContextSupport interface if the consent tools should support twig.
Twig integration
The extension provides Twig filters and functions to use consent functionality directly in Twig templates.
The consent tool must implement \Hofff\Contao\Consent\Bridge\WithGenericContextSupport to support Twig rendering.
hofff_consent_required — Function
Checks whether consent is required for a given consent ID. Returns true if the active consent tool requires
consent, false otherwise (also when no consent tool is active or the ID is invalid).
{# Check by consent ID string #} {% if hofff_consent_required('my-consent-id') %} {# Consent is required, render placeholder or alternative content #} {% endif %} {# Check using the Twig context (reads hofff_consent_bridge_tag automatically) #} {% if hofff_consent_required(_context) %} {# Consent is required #} {% endif %}
hofff_consent_content — Filter
Wraps HTML content according to the requirements of the active consent tool. If consent is required, the output is transformed by the consent tool (e.g. replaced with a placeholder). An optional custom placeholder template and additional data can be passed.
If no consent tool is active or the consent ID is invalid, the original HTML is returned unchanged.
{# Basic usage #} {{ html_content|hofff_consent_content('my-consent-id') }} {# With a custom placeholder template #} {{ html_content|hofff_consent_content('my-consent-id', 'my_placeholder_template') }} {# With a custom placeholder template and additional data passed to the consent tool #} {{ html_content|hofff_consent_content('my-consent-id', 'my_placeholder_template', {title: 'My Title'}) }}
The filter can also be applied to larger blocks using the {% apply %} tag:
{% apply hofff_consent_content('my-consent-id') %}
<iframe src="https://example.com/embed" width="560" height="315"></iframe>
{% endapply %}
{# With a custom placeholder template #}
{% apply hofff_consent_content('my-consent-id', 'my_placeholder_template') %}
<iframe src="https://example.com/embed" width="560" height="315"></iframe>
{% endapply %}
{# With additional data #}
{% apply hofff_consent_content('my-consent-id', 'my_placeholder_template', {title: 'My Title'}) %}
<iframe src="https://example.com/embed" width="560" height="315"></iframe>
{% endapply %}
hofff_consent_raw — Filter
Applies consent requirements to raw HTML content (e.g. inline scripts or tracking code) without adding a visual placeholder. This is intended for hidden markup that should be managed by the consent tool but does not need a visible fallback.
If no consent tool is active or the consent ID is invalid, the original HTML is returned unchanged.
{# Basic usage #} {{ raw_script|hofff_consent_raw('my-consent-id') }} {# With additional data passed to the consent tool #} {{ raw_script|hofff_consent_raw('my-consent-id', {key: 'value'}) }}
The filter can also be applied to blocks using the {% apply %} tag:
{% apply hofff_consent_raw('my-consent-id') %}
<script type="text/javascript">
// tracking code
</script>
{% endapply %}
{# With additional data #}
{% apply hofff_consent_raw('my-consent-id', {key: 'value'}) %}
<script type="text/javascript">
// tracking code
</script>
{% endapply %}
hofff/contao-consent-bridge 适用场景与选型建议
hofff/contao-consent-bridge 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.93k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2020 年 03 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cookies」 「consent」 「GDPDR」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hofff/contao-consent-bridge 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hofff/contao-consent-bridge 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hofff/contao-consent-bridge 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Add a configurable cookie consent banner to the website.
Use Klaro! Consent Manager in Contao CMS
Helper class to easily work with cookies.
Symfony 8 bundle for GDPR/DSGVO cookie consent with Google Consent Mode v2, Twig components, Stimulus.js, and AssetMapper. Supports cookie, Doctrine, or combined storage. Includes YouTube, Vimeo, Google Maps embed components.
Symfony bundle for adding a GDPR consent banner
统计信息
- 总下载量: 6.93k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 9
- 依赖项目数: 7
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0-or-later
- 更新时间: 2020-03-19