定制 hofff/contao-consent-bridge 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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 %}

统计信息

  • 总下载量: 6.93k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 7
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-or-later
  • 更新时间: 2020-03-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固