Skip to content

Latest commit

 

History

History
136 lines (116 loc) · 3.44 KB

README.md

File metadata and controls

136 lines (116 loc) · 3.44 KB

Gdpr Bundle

Installation

Install package

composer require fluffy-factory/gdpr-bundle

Install assets

php bin/console asset:install

Configuration

# config/packages/gdpr.yaml

gdpr:
  redirection_url: 'fluffy_gdpr' # If you don't specify a route, the user will be redirected to the route he is on.
  btn:
    deny: true
    accept: true
  design:
    disable: false
    bg_color: '#292e33'
    text_color: '#ffffff'
    btn_deny_bg_color: '#D23A4B'
    btn_deny_text_color: '#ffffff'
    btn_allow_bg_color: '#0ED198'
    btn_allow_text_color: '#ffffff'

  cookies:
    my_cookie_required:
      name: cookie_name
      description: "description ..."
      detail: "expiration date ..."
      required: true
    my_cookie_optionnal:
      name: cookie_name_1
      description: "description ..."
      detail: "expiration date ..."
      required: false

NOTE
If the design.disable property is true so the style attribute will not be added to template's elements.

Route

The bundle provide the route 'fluffy_gdpr'. You can edit the content to explain your cookies and configure them.

# config/routes/gdpr.yaml

gdpr:
  resource: "@GdprBundle/Controller/GdprController.php"
  type: annotation
{# privacy.html.twig #}

{% block required_cookies_table %}
    <h2 id="params">{{ 'cookies.required.title'|trans({},'GdprBundle') }}</h2>
    <table>
        <thead>
        <tr>
            <th>{{ 'cookies.name'|trans({},'GdprBundle') }}</th>
            <th>{{ 'cookies.description'|trans({},'GdprBundle') }}</th>
            <th>{{ 'cookies.details'|trans({},'GdprBundle') }}</th>
        </tr>
        </thead>
        <tbody>
        {% for cookie in required_cookies %}
            <tr>
                <td>{{ cookie.name|trans({},'GdprBundle') }}</td>
                <td>{{ cookie.description|trans({},'GdprBundle') }}</td>
                <td>{{ cookie.detail|trans({},'GdprBundle') }}</td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
{% endblock %}

{% block optionnal_cookies_table %}
    <h2>{{ 'cookies.optionnal.title'|trans({},'GdprBundle') }}</h2>

    {{ form_start(form) }}
    {% for key, optionnal in optionnal_cookies %}
        {{ optionnal.name }}
        {{ form_widget(form[key]) }}
        <p>{{ optionnal.description }}</p>
        <p>{{ optionnal.detail }}</p>
    {% endfor %}

    <button type="submit">{{ 'cookies.accept'|trans({},'GdprBundle') }}</button>
    {{ form_end(form) }}
{% endblock %}
Twig

Add this script tag, the cookies.js script need it to knows which cookies write when the user accept or deny the privacy policy from the cookie_bar.html.twig

<head>
    <script type="text/javascript">
        var optionnalCookies = {{ getOptionnalCookiesNames() }}
    </script>
</head>

{% block javascripts %}
    <script src="{{ asset('bundles/gdpr/js/cookies.js') }}"></script>
{% endblock %}

Add stylesheets

{% block stylesheets %}
    <link rel="stylesheet" href="{{ asset('bundles/gdpr/css/style.css') }}">
{% endblock %}

showCookieBar() check if the user already has all your cookies from the configuration file.

{% if showCookieBar() %}
    {% include '@Gdpr/cookie_bar.html.twig' %}
{% endif %}

In case of optionnals cookies you can manage them in case-by-case with the twig function allowedCookie('cookie_name')

{% if allowedCookie('google_analytics') %}
   {# insert your code here ... #}
{% endif %}