albertborsos / yii2-gdpr-cookie-consent
GDPR compatible Cookie Consent widget allows the user to choose which kind of cookies they want to accept.
Installs: 22 915
Dependents: 1
Suggesters: 0
Security: 0
Stars: 11
Watchers: 8
Forks: 7
Open Issues: 3
Type:yii2-extension
Requires
- php: >=5.6.0
- 2amigos/yii2-switch-widget: ^1.0
- albertborsos/yii2-ddd: ~0.2
- bower-asset/cookieconsent: ~3.1
- yiisoft/yii2: ~2.0.0
Requires (Dev)
- codeception/codeception: ^2.4
- codeception/mockery-module: ^0.2.2
- codeception/specify: ~0.4.6
- codeception/verify: ~0.4.0
- mito/yii2-coding-standards: ~2.0.0@beta
- satooshi/php-coveralls: ~1.0
- dev-master
- 1.3.0
- 1.2.5
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 1.0.0-beta2
- 1.0.0-beta1
- 0.1.0-beta10
- 0.1.0-beta9
- 0.1.0-beta8
- 0.1.0-beta7
- 0.1.0-beta6
- 0.1.0-beta5
- 0.1.0-beta4
- 0.1.0-beta3
- 0.1.0-beta2
- 0.1.0-beta1
- dev-dependabot/composer/guzzlehttp/psr7-1.9.1
- dev-dependabot/composer/guzzlehttp/guzzle-6.5.8
This package is auto-updated.
Last update: 2024-11-19 22:25:00 UTC
README
GDPR compatible Cookie Consent widget allows the user to choose which kind of cookies they want to accept.
Installation
The preferred way to install this extension is through composer.
Run
composer require --prefer-dist albertborsos/yii2-gdpr-cookie-consent
Usage
add the component to your config file:
<?php return [ // ... 'components' => [ // ... 'cookieConsent' => [ 'class' => \albertborsos\cookieconsent\Component::class, 'urlSettings' => ['/site/cookie-settings'], 'urlPrivacyPolicy' => ['/site/privacy-policy'], 'documents' => [ ['name' => 'Privacy Policy', 'url' => ['/docs/privacy-policy.pdf']], ], 'disabledCategories' => [ \albertborsos\cookieconsent\helpers\CookieHelper::CATEGORY_BEHAVIOR, ], ], // ... 'i18n' => [ // ... 'translations' => [ 'cookieconsent/*' => [ 'class' => 'yii\i18n\PhpMessageSource', 'basePath' => '@vendor/albertborsos/yii2-gdpr-cookie-consent/src/messages', ], ], // ... ], ], // ... ];
Register the widget in your layout. For example in a _cookieconsent.php
partial view.
<?php /** @var \albertborsos\cookieconsent\Component $component */ $component = Yii::$app->cookieConsent; $component->registerWidget([ 'policyLink' => ['/default/cookie-settings'], 'policyLinkText' => \yii\helpers\Html::tag('i', null, ['class' => 'fa fa-cog']) . ' Beállítások', 'pluginOptions' => [ 'expiryDays' => 365, 'hasTransition' => false, 'revokeBtn' => '<div class="cc-revoke {{classes}}">Cookie Policy</div>', ], ]);
Add the cookie settings form to any of your controller:
<?php namespace app\controllers; class SiteController extends \yii\web\Controller { public function actions() { return [ 'cookie-settings' => \albertborsos\cookieconsent\actions\CookieSettingsAction::class, 'privacy-policy' => \albertborsos\cookieconsent\actions\PrivacyPolicyAction::class, ]; } }
Check your relevant widget is allowed by the user or not with the CookieConsent helper class in the following way:
<?php use \albertborsos\cookieconsent\helpers\CookieHelper; use \albertborsos\cookieconsent\Component; if(CookieHelper::isAllowedType(CookieHelper::TYPE_GOOGLE_ANALYTICS)){ // register GA script } if(CookieHelper::isAllowedCategory(CookieHelper::CATEGORY_BEHAVIOR)){ // register hotjar script }