Developed with love by KnpLabs Hire us for your project!
20

xsolve-cookie-acknowledgement-bundle

by xsolve-pl

This bundle provides information about an cookies usage, which is forced by European Union by so-called EU cookie law.

About

knpbundles.com

SensioLabsInsight

This bundle provides information about an cookies usage, which is forced by European Union by so-called EU cookie law.

It includes:

  • fast & easy integration and short learning curve
  • automatic cookie bar injection on the bottom of the page
  • ability to manually inject cookie bar (for example for iframes)
  • ability to change text and "close button" name
  • locale aware
  • ability to provide own cookie bar template

This bundle requires Multibyte String extension.

Example usage

Installation

1) Add to composer.json

"require": {
    "xsolve-pl/xsolve-cookie-acknowledgement-bundle": "1.0.*"
},

2) Install dependencies

composer install

3) Run the bundle in app/AppKernel.php

public function registerBundles()
{
    return array(
        // ...
        new Xsolve\CookieAcknowledgementBundle\XsolveCookieAcknowledgementBundle(),
    );
}

Usage

For all static pages

By default the cookie bar will be visible on every page after turning on bundle.

For iframes

Disable response injection in app/config/config.yml

xsolve_cookie_acknowledgement:
    response_injection: false

Include cookie bar in appropriate location

{% include 'XsolveCookieAcknowledgementBundle::cookie_acknowledgement_bar.html.twig' %}

Configuration options

Configuration can be adjusted in 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

Altering cookie bar texts

Place tranlations file in your app directory:

app/Resources/translations/XsolveCookieAcknowledgementBundle.en.yml

And change texts

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.

Altering cookie bar apperance

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:

#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.

Altering whole cookie bar template

You use your own template by setting it in the configuration (app/config/config.yml):

xsolve_cookie_acknowledgement:
    template: ::custom_cookie_bar.html.twig

In above case template is located in app/Resources/custom_cookie_bar.html.twig

Also base template can be reused be Twig extension (two blocks are used: xsolve_cookie_message and xsolve_cookie_message_js), see example below:

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

Automated testing

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

<testsuite name="XSolve Cookie Acknowledgement Bundle Suite">
    <directory>../vendor/xsolve-pl/xsolve-cookie-acknowledgement-bundle/Xsolve/CookieAcknowledgementBundle/Tests/</directory>
</testsuite>

And run

phpunit -c app/
xsolve_cookie_acknowledgement:
response_injection: true
template: XsolveCookieAcknowledgementBundle::cookie_acknowledgement_bar.html.twig
  • Merge pull request #8 from vladab/patch-1
    By web-flow, 1 year ago
  • Symfony 3.* compatibility
    By , 3 years ago
  • Merge pull request #6 from krzysztof-gzocha-xsolve/master
    By , 4 years ago
  • cr fixes
    By krzysztof-gzocha-xsolve, 4 years ago
  • Using localStorage instead of sessionStorage
    By krzysztof-gzocha-xsolve, 5 years ago
  • Better file names
    By krzysztof-gzocha-xsolve, 5 years ago
  • Synchro
    By krzysztof-gzocha-xsolve, 5 years ago
  • Removed cookie expiration time
    By krzysztof-gzocha-xsolve, 5 years ago
  • Using window.sessionStorage instead of cookies + small tweaks
    By krzysztof-gzocha-xsolve, 5 years ago
  • Merge pull request #5 from krzysztof-gzocha-xsolve/devel
    By wowo, 6 years ago
  • Cookie path
    By krzysztof-gzocha-xsolve, 6 years ago
  • Added SensioLabsInsight platinum badge do Readme
    By wowo, 6 years ago
  • Removed executable permission from files that don't need this
    By Wojciech Sznapka, 6 years ago
  • Update README.md
    By wowo, 6 years ago
  • Merge pull request #4 from tristanbes/master
    By wowo, 6 years ago
  • [CS] Minor improvements to readability
    By Tristan Bessoussa, 6 years ago
  • Update README.md
    By wowo, 6 years ago
  • Update README.md
    By wowo, 6 years ago
  • Update README.md
    By wowo, 6 years ago
  • Merge pull request #3 from xsolve-pl/fix/style-fixes
    By wowo, 6 years ago
  • Spelling in README
    By Wojciech Sznapka, 6 years ago
  • Merge branch 'fix/style-fixes' of https://github.com/xsolve-pl/xsolve-cookie-acknowledgement-bundle into fix/style-fixes
    By Wojciech Sznapka, 6 years ago
  • Tests adjustments
    By Wojciech Sznapka, 6 years ago
  • Update README.md
    By wowo, 6 years ago
  • README adjustments and example screenshot
    By Wojciech Sznapka, 6 years ago
  • Readme update with use cases and examples
    By Wojciech Sznapka, 6 years ago
  • Refactored template and added default styles for cookie bar
    By Wojciech Sznapka, 6 years ago
  • Code style fixes
    By Wojciech Sznapka, 6 years ago
  • Changed default configuration values
    By Wojciech Sznapka, 6 years ago
  • Adjusted translations
    By Wojciech Sznapka, 6 years ago