quentincharrier / cookie-consent-bundle
Sylius 插件,用于实现 Cookie Consent 以符合 AVG/GDPR。
Requires
- php: ^7.2
- doctrine/annotations: ^1.6
- doctrine/doctrine-bundle: ^1.10 || ^2.0
- doctrine/orm: ^2.5
- symfony/asset: ^3.4 || ^4.2 || ^5.0
- symfony/dependency-injection: ^3.4 || ^4.2 || ^5.0
- symfony/doctrine-bridge: ^3.4 || ^4.2 || ^5.0
- symfony/expression-language: ^3.4 || ^4.2 || ^5.0
- symfony/form: ^3.4 || ^4.2 || ^5.0
- symfony/framework-bundle: ^3.4 || ^4.2 || ^5.0
- symfony/http-foundation: ^3.4 || ^4.2 || ^5.0
- symfony/templating: ^3.4 || ^4.2 || ^5.0
- symfony/translation: ^3.4 || ^4.2 || ^5.0
- symfony/twig-bridge: ^3.4 || ^4.2 || ^5.0
- symfony/twig-bundle: ^3.4 || ^4.2 || ^5.0
- twig/twig: ^2.6 || ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.14
- phpunit/phpunit: ^7.5
- symfony/yaml: ^3.4 || ^4.2 || ^5.0
README
Sylius 的 Cookie Consent 插件
Sylius 插件,用于将 Cookie Consent 添加到您的网站,以符合 AVG/GDPR 对于 Cookie 的规定。
安装
步骤 1:使用 composer 下载
在 Sylius 应用程序中运行以下命令以安装和集成 Cookie Consent 插件到您的应用程序
composer require quentinCharrier/cookie-consent-bundle
步骤 2:启用插件
当不使用 symfony flex 时,请手动在内核中启用插件
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new ConnectHolland\CookieConsentBundle\CHCookieConsentBundle(), // ... ); }
步骤 3:启用路由
当不使用 symfony flex 时,请手动启用插件的路由
# app/config/routing.yml ch_cookie_consent: resource: "@CHCookieConsentBundle/Resources/config/routing.yaml"
步骤 4:根据需要配置
使用以下可能的设置配置您的 Cookie Consent
ch_cookie_consent: theme: 'light' # light, dark categories: # Below are the default supported categories - 'analytics' - 'tracking' - 'marketing' - 'social_media' use_logger: true # Logs user actions to database
步骤 5:添加 Cookie 政策路径
配置到您的 Cookie 政策页面的路径
# app/config/twig.yml twig: globals: path_to_cookie_policy: '/cookie-policy' # to change to your custom path
步骤 5:添加 Cookie 政策路径
配置到您的 Cookie 政策页面的路径
# app/config/twig.yml twig: globals: path_to_cookie_policy: '/cookie-policy' # to change to your custom path
使用方法
Twig 实现
在任何您喜欢的地方通过 render_esi(以防止缓存)加载 cookie consent
- 模板:渲染带有选择允许或不允许的 cookie 类别的表单的同意模态框
{{ render_esi(path('ch_cookie_consent.show')) }}
- 模板:渲染尚未设置的 cookie 通知横幅。
{{ render_esi(path('ch_cookie_consent.show_if_cookie_consent_not_set')) }}
如果您想使用特定的区域设置加载 cookie consent,可以传递区域设置作为参数
{{ render_esi(path('ch_cookie_consent.show', { 'locale' : 'en' })) }} {{ render_esi(path('ch_cookie_consent.show_if_cookie_consent_not_set', { 'locale' : app.request.locale })) }}
Cookie
当用户提交表单时,偏好设置将保存为 Cookie。Cookie 的有效期为 1 年。以下 Cookie 被保存
- Cookie_Consent:提交日期
- Cookie_Consent_Key:作为用户提交的 Cookie Consent 的标识符生成的密钥
- Cookie_Category_[CATEGORY]:用户选择的值(《true》或《false》)
日志记录
AVG/GDPR 要求网站管理员可以解释所有用户提供的 Cookie 偏好。为此,我们将所有 Cookie 偏好记录到数据库中。IP 地址已被匿名化。此选项可以在配置中禁用。
主题
Twig 扩展
以下 Twig 扩展函数可用
chcookieconsent_isCategoryAllowedByUser 检查用户是否为特定 cookie 类别授予了权限
{% if chcookieconsent_isCategoryAllowedByUser('analytics') == true %} ... {% endif %}
chcookieconsent_isCookieConsentSavedByUser 检查用户是否保存了任何 cookie 偏好
{% if chcookieconsent_isCookieConsentSavedByUser() == true %} ... {% endif %}
自定义
类别
您可以通过更改配置并确保这些类别有可用的翻译来添加或删除任何类别。
翻译
所有文本都可以通过覆盖 CHCookieConsentBundle 翻译文件来更改 Symfony 翻译。
样式
CHCookieConsentBundle 附带默认样式。在 Resources/assets/css/cookie_consent.scss 中有一个 sass 文件,在 Resources/public/css/cookie_consent.css 中有一个构建后的 css 文件。可以通过设置 sass 文件中可用的变量轻松调整颜色。
要安装这些资产,请运行
php bin/console assets:install
要安装主题资产,请运行
php bin/console sylius:theme:assets:install
并在模板中包含样式
{% include "@CHCookieConsent/cookie_consent_styling.html.twig" %}
JavaScript
通过加载 Resources/public/js/cookie_consent.js,cookie consent 将通过 AJAX 提交,并将 cookie consent 显示在网站顶部,同时将网站的其他部分向下推。
模板主题
您可以通过将模板放置在项目中来覆盖模板
# app/Resources/CHCookieConsentBundle/views/cookie_consent.html.twig {% extends '@!CHCookieConsent/cookie_consent.html.twig' %} {% block title %} Your custom title {% endblock %}