XSolve Cookie Acknowledgement Bundle to handle new privacy law
This bundle provides information about an cookies usage, which is forced by European Union by so-called EU cookie law., (*3)
It includes:, (*4)
This bundle requires Multibyte String extension., (*5)
, (*6)
1) Add to composer.json, (*7)
"require": { "xsolve-pl/xsolve-cookie-acknowledgement-bundle": "1.0.*" },
2) Install dependencies, (*8)
composer install
3) Run the bundle in app/AppKernel.php, (*9)
public function registerBundles() { return array( // ... new Xsolve\CookieAcknowledgementBundle\XsolveCookieAcknowledgementBundle(), ); }
By default the cookie bar will be visible on every page after turning on bundle., (*10)
Disable response injection in app/config/config.yml, (*11)
xsolve_cookie_acknowledgement: response_injection: false
Include cookie bar in appropriate location, (*12)
{% include 'XsolveCookieAcknowledgementBundle::cookie_acknowledgement_bar.html.twig' %}
Configuration can be adjusted in app/config/config.yml, (*13)
xsolve_cookie_acknowledgement: response_injection: true # default true template: custom_cookie_bar.html.twig # twig template name, default: XsolveCookieAcknowledgementBundle::cookie_acknowledgement_bar.html.twig
Place tranlations file in your app directory:, (*14)
app/Resources/translations/XsolveCookieAcknowledgementBundle.en.yml
And change texts, (*15)
cookie.message: My message cookie.message.accept: Accept button text
Of course you can set up those texts in as many locales as you want., (*16)
By default cookie bar comes with some default styles. If you wish to change those, use CSS. For example you may want pink background with placement on top of the page:, (*17)
#cookie-law-info-bar { background: pink !important; top: 50px !important; bottom: auto !important; }
Please note that every style needs !important
to override provided inline styles., (*18)
You use your own template by setting it in the configuration (app/config/config.yml):, (*19)
xsolve_cookie_acknowledgement: template: ::custom_cookie_bar.html.twig
In above case template is located in app/Resources/custom_cookie_bar.html.twig, (*20)
Also base template can be reused be Twig extension (two blocks are used: xsolve_cookie_message and xsolve_cookie_message_js), see example below:, (*21)
{% 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 %}
There are fe simple test to make sure that everything works fine. To run tests include this bundle into some Symfony2 project (Symfony Standard Edition is enough). Then put testsuite in app/phpunit.xml, (*22)
<testsuite name="XSolve Cookie Acknowledgement Bundle Suite"> <directory>../vendor/xsolve-pl/xsolve-cookie-acknowledgement-bundle/Xsolve/CookieAcknowledgementBundle/Tests/</directory> </testsuite>
And run, (*23)
phpunit -c app/