定制 kunstmaan/cookie-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kunstmaan/cookie-bundle

Composer 安装命令:

composer require kunstmaan/cookie-bundle

包简介

The Kunstmaan Cookie Bundle provides a cookie bar; detailed pop-up window and a similar page explaining each type of cookie used on the website.

README 文档

README

The Kunstmaan Cookie Bundle provides a cookie bar; detailed pop-up window and a similar page explaining each type of cookie used on the website.

All provide the ability to accept or decline certain cookies.

Original Contributors

Username Avatar
@sandergo90 sandergo90
@diskwriter diskwriter
@indrikenens indrikenens
@FVKVN FVKVN
@dbeerten dbeerten
@treeleaf treeleaf
@KMBenjaminSchodts KMBenjaminSchodts
@sector32 treeleaf

Enabling the bundle

Add to Appkernel.php

Add to routing.yml

KunstmaanCookieBundle:
    resource: "@KunstmaanCookieBundle/Resources/config/routing.yml"
    prefix:   /{_locale}/
    requirements:
      _locale: "%requiredlocales%"

Two ways to view the cookie implementation

1: Login into the CMS

2: enable the cookie bundle under Settings -> Cookie configuration

Importing the cookie bundle

Show cookie on page

Add following block to the main layout of your website

{# Kuma Cookie Bar #}
{% block kumacookiebar %}
    <kuma-cookie-bar></kuma-cookie-bar>
{% endblock %}

CSS: First Method

Apply all CSS by importing the legal.scss file into the vendors file of your project

@import "vendor/kunstmaan/cookie-bundle/src/Resources/ui/scss/legal";

CSS: Second method

Import the Kunstmaan Cookie Bundle variables and imports to be overridden. Copy the files at the following path to your project folder.

vendor/kunstmaan/cookie-bundle/Resources/ui/scss/config/_variables.scss vender/kunstmaan/cookie-bundle/Resources/ui/scss/config/_legal-imports.scss

Alter variables and comment imports to fit the project's styling.

Javascript

Via ES Module pattern

import '../../../../../../vendor/kunstmaan/cookie-bundle/bin/';

Via buildtool

You can include the compiled version in your buildtool - or directly in a template - via the following URL:

vendor/kunstmaan/cookie-bundle/src/Resources/ui/bin/index.js

Global methods

The CookieBundle exposes some utility methods that you can include in your project.

import {getKmccCookies} from '<VENDOR_LOCATION>/kunstmaan/cookie-bundle/bin/'; // Returns the settings of all the cookies.
import {hasAllowedDatalayers} from '<VENDOR_LOCATION>/kunstmaan/cookie-bundle/bin/'; // Shorthand to check if you're allowed to use dataLayers in this
 project.
import {asyncDomInitiator} from '<VENDOR_LOCATION/kunstmaan/cookie-bundle/bin/'; // This is to initialize async inserted Cookie Bundle Components. Expects 1 param: an object like the following: {nodeTree: <HTMLElement>}

Both these methods are also available on the global scope for projects that do not have bundlers:

window.kmcc.getKmccCookies(); 
window.kmcc.hasAllowedDatalayers(); 
window.kmcc.asyncDomInitiator({
    nodeTree: <HTMLElement>
});

Commands

Copy Cookiebar Resources to your project

Default command:

php bin/console kuma:generate:legal --prefix foo_ --demosite

or, if you have previously generated files and wish to override them: php bin/console kuma:generate:legal --prefix will_ --demosite --overrideFiles

Migrate

php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate

Generate fixtures

php bin/console d:f:l --fixtures src/foo/AppBundle/DataFixtures/ORM/LegalGenerator/DefaultFixtures.php --append

Add the optin pagepart to your form pages.

We added an extra LegalOptInPagePart that behaves like a checkbox but adds the extra of a link to the privacy policy directly.

The pagepart will be generated in your bundle and you will have to include it in your pagepart configuration yaml file.

    - { name: 'Opt In', class: Foo\WebsiteBundle\Entity\PageParts\LegalOptInPagePart }

Easily generate links for your project that open the cookie modal:

Add by using this snippet you can easily add the necessary links to your project in custom places like a footer:

{% if is_granted_for_cookie_bundle(app.request) %}
    {% set legalLinks = ['legal_privacy_policy', 'legal_cookie_preferences', 'legal_contact'] %}
    {% for internalName in legalLinks %}
        {% set node = nodemenu.getNodeByInternalName(internalName) %}
        {% if (node is not null) %}
            -
            <a data-target="{{ internalName }}" data-url="{{ path('kunstmaancookiebundle_legal_modal', {'internal_name': internalName}) }}"
                class="sub-footer__info__link js-kmcc-extended-modal-button">
                {{ node.title }}
            </a>
        {% endif %}
    {% endfor %}
{% endif %}

Overriding translations

If you want to override the translations of the cookie bundle, you need to add the following configuration in your config.yml beneath the existing kunstmaan_translator config.

kunstmaan_translator:
    default_bundle: custom
    bundles:
      - KunstmaanCookieBundle
      - YourOwnBundle

Add visitor type to google analytics

We added the possibility to push a datalayer to google analytics with the type of visitor viewing your website. A new Config entity has been added where you can add the ip-addresses of clients or internal. Those ip's will be checked on request and a datalayer will be pushed.

If you want to use this functionality, please read the documentation for the Config Bundle to setup. When you did this, add the following snippet to your config.yml.

kunstmaan_config:
    entities:
        - Kunstmaan\CookieBundle\Entity\CookieConfig

Following input field should be added to your layout.html.twig. You can add in beneath the kuma-cookie-bar element.

<input type="hidden" value="{{ get_visitor_type(app.request) }}" id="kmcc-visitor-type"/>

Increase version number when adding cookies/types or changing stuff the requires new cookie consent.

In the cookie configuration, there is a version number available. This version number can be increased in the CMS.

Contributing

We love contributions! If you're submitting a pull request, please follow the guidelines in the Submitting pull requests

kunstmaan/cookie-bundle 适用场景与选型建议

kunstmaan/cookie-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.31k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 08 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「cms」 「kunstmaan」 「gdpr」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 kunstmaan/cookie-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 kunstmaan/cookie-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 kunstmaan/cookie-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 9.31k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 30
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 11
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-08-06