vladab / cookie-acknowledgement-bundle
处理新隐私法的Cookie确认包
This package is not auto-updated.
Last update: 2024-09-23 13:57:37 UTC
README
此包提供有关cookie使用的详细信息,这是由欧盟所谓的欧盟cookie法强制规定的。
它包括
- 快速简单集成和短的学习曲线
- 自动在页面底部注入cookie条
- 手动注入cookie条的能力(例如对于iframe)
- 更改文本和"关闭按钮"名称的能力
- 本地化感知
- 提供自己的cookie条模板的能力
此包需要Multibyte String扩展。
安装
-
添加到composer.json
"require": { "xsolve-pl/xsolve-cookie-acknowledgement-bundle": "1.0.*" },
-
安装依赖
composer install
-
在app/AppKernel.php中运行包
public function registerBundles() { return array( // ... new Xsolve\CookieAcknowledgementBundle\XsolveCookieAcknowledgementBundle(), ); }
用法
对于所有静态页面
默认情况下,在启用包后,cookie条将在每个页面上可见。
对于iframe
在app/config/config.yml中禁用响应注入
xsolve_cookie_acknowledgement:
response_injection: false
在适当的位置包含cookie条
{% include 'XsolveCookieAcknowledgementBundle::cookie_acknowledgement_bar.html.twig' %}
配置选项
配置可以在app/config/config.yml中调整
xsolve_cookie_acknowledgement:
response_injection: true # default true
template: custom_cookie_bar.html.twig # twig template name, default: XsolveCookieAcknowledgementBundle::cookie_acknowledgement_bar.html.twig
更改cookie条文本
将翻译文件放在您的应用程序目录中
app/Resources/translations/XsolveCookieAcknowledgementBundle.en.yml
并更改文本
cookie.message: My message
cookie.message.accept: Accept button text
当然,您可以在您想要的任何区域设置中设置这些文本。
更改cookie条外观
默认情况下,cookie条带有一些默认样式。如果您希望更改这些,请使用CSS。例如,您可能希望使用粉色背景并放置在页面顶部
#cookie-law-info-bar {
background: pink !important;
top: 50px !important;
bottom: auto !important;
}
请注意,每个样式都需要!important
来覆盖提供的内联样式。
更改整个cookie条模板
您可以通过在配置中设置它(app/config/config.yml)来使用自己的模板
xsolve_cookie_acknowledgement:
template: ::custom_cookie_bar.html.twig
在上面的例子中,模板位于app/Resources/custom_cookie_bar.html.twig
此外,基础模板可以通过Twig扩展重用(使用两个块:xsolve_cookie_message和xsolve_cookie_message_js),请参阅下面的示例
{% extends "XsolveCookieAcknowledgementBundle::cookie_acknowledgement_bar.html.twig" %}
{% block xsolve_cookie_message %}
{{ parent() }}
<div>This is something custom</div>
{% endblock %}
{% block xsolve_cookie_message_js %}
{{ parent() }}
<script type="text/javascript">
document.getElementById('js-cookie-law-close-button').onclick = function () {
alert('Got ya!');
}
</script>
{% endblock %}
自动测试
有一些简单的测试来确保一切正常工作。要运行测试,请将此包包含到某个Symfony2项目中(Symfony标准版就足够了)。然后将测试套件放入app/phpunit.xml
<testsuite name="XSolve Cookie Acknowledgement Bundle Suite">
<directory>../vendor/xsolve-pl/xsolve-cookie-acknowledgement-bundle/Xsolve/CookieAcknowledgementBundle/Tests/</directory>
</testsuite>
然后运行
phpunit -c app/