bizley / cookiemonster
Yii extension to manage cookie warning.
Fund package maintenance!
bizley
Installs: 12 185
Dependents: 1
Suggesters: 0
Security: 0
Stars: 19
Watchers: 5
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- php: >=5.4
- yiisoft/yii2: *
Requires (Dev)
- php: >=7.2
- infection/infection: *
- phpunit/phpunit: ^8.5
- roave/security-advisories: dev-master
This package is auto-updated.
Last update: 2024-10-29 10:01:39 UTC
README
Yii 2 extension to manage cookie warning
What is it for?
In 2009, the European Union sought new regulations as part of an "e-privacy" directive, seeing cookies as a potential
threat to privacy, because users often don't know they are being tracked.
This extension adds the information about cookies for the Yii website.
Requirements
Yii 2
Installation
Get it through composer by adding the package to your composer.json:
{ "require": { "bizley/cookiemonster": "*" } }
Or run composer require bizley/cookiemonster
.
Usage
Add this code in your main template file just before <?php $this->endBody() ?>
<?= \bizley\cookiemonster\CookieMonster::widget() ?>
This will render widget with all default options (and 'top' layout).
If you want to configure it add options array.
<?= \bizley\cookiemonster\CookieMonster::widget([/* options here */]) ?>
All options (and options' options) are described below.
For example if you want to use custom message on the button and use 'bottom' layout set:
<?= \bizley\cookiemonster\CookieMonster::widget([
'content' => [
'buttonMessage' => 'OK', // instead of default 'I understand'
],
'mode' => 'bottom'
]); ?>
Configuration
You can set widget options by passing array to the widget() method with the following keys:
box
- array CSS class and styles and HTML options for divcontent
- array warning and button messagecookie
- array cookie optionsmode
- string widget layout selectionparams
- mixed user's parameters to pass to the custom widget layout
box
options
addButtonStyle
- array list of button CSS style options to be added or replaced with new values i.e. 'padding-right' => '20px', 'font-weight' => 'bold'addInnerStyle
- array list of inner div CSS style options to be added or replaced with new valuesaddOuterStyle
- array list of outer div CSS style options to be added or replaced with new valuesbuttonHtmlOptions
- array list of button HTML options to be added (except style and class)classButton
- string button class or classes (separated by spaces), default 'CookieMonsterOk'classInner
- string inner div class or classes (separated by spaces)classOuter
- string outer div class or classes (separated by spaces), default 'CookieMonsterBox'innerHtmlOptions
- array list of inner div HTML options to be added (except style and class)outerHtmlOptions
- array list of outer div HTML options to be added (except style and class)replaceButtonStyle
- array list of button CSS style options to be replaced with new values or removed i.e. 'margin-left' => '10px', 'font-size' => falsereplaceInnerStyle
- array list of inner div CSS style options to be replaced with new values or removedreplaceOuterStyle
- array list of outer div CSS style options to be replaced with new values or removedsetButtonStyle
- array list of button CSS style options to be set replacing the default onessetInnerStyle
- array list of inner div CSS style options to be set replacing the default onessetOuterStyle
- array list of outer div CSS style options to be set replacing the default onesview
- string path to the custom view (required if $mode is set to 'custom'), for views outside the widget folder use alias path i.e. '@app/views/cookie'
content
options
buttonMessage
- string button original message as in Yii::t() $message, default 'I understand'buttonParams
- array parameters to be applied to the buttonMessage as in Yii::t() $params, default array()category
- string message category as in Yii::t() $category, default 'app'language
- string target language as in Yii::t() $language, default nullmainMessage
- string main original message as in Yii::t() $message, default 'We use cookies on our websites to help us offer you the best online experience. By continuing to use our website, you are agreeing to our use of cookies. Alternatively, you can manage them in your browser settings.'mainParams
- array parameters to be applied to the mainMessage as in Yii::t() $params, default array()
cookie
options
domain
- string domain name for the cookie, default host portion of the current document locationexpires
- integer number of days this cookie will be valid for, default 30max-age
- integer max cookie age in secondspath
- string path for the cookie, default '/'secure
- boolean whether cookie should be transmitted over secure protocol as https, default falsesameSite
- string 'lax' (default), 'strict', or 'none'
mode
possible values
bottom
- bottom stripbox
- bottom right boxcustom
- custom mode defined by user (requiresbox[view]
to be set)top
- top strip, default
Default layouts
bottom
<div style="display:none;z-index:10000;position:fixed;background-color:#fff;font-size:12px;color:#000;bottom:0;left:0;width:100%;box-shadow:0 -2px 2px #000" class="CookieMonsterBox"> <div style="margin:10px" class=""> We use cookies on our websites to help us offer you the best online experience. By continuing to use our website, you are agreeing to our use of cookies. Alternatively, you can manage them in your browser settings.<button style="margin-left:10px" class="CookieMonsterOk" type="button">I understand</button> </div> </div>
box
<div style="display:none;z-index:10000;position:fixed;background-color:#fff;font-size:12px;color:#000;bottom:20px;right:20px;width:300px;box-shadow:-2px 2px 2px #000;border-radius:10px" class="CookieMonsterBox"> <div style="margin:10px" class=""> We use cookies on our websites to help us offer you the best online experience. By continuing to use our website, you are agreeing to our use of cookies. Alternatively, you can manage them in your browser settings.<button style="margin-left:10px" class="CookieMonsterOk" type="button">I understand</button> </div> </div>
top
<div style="display:none;z-index:10000;position:fixed;background-color:#fff;font-size:12px;color:#000;top:0;left:0;width:100%;box-shadow:0 2px 2px #000" class="CookieMonsterBox"> <div style="margin:10px" class=""> We use cookies on our websites to help us offer you the best online experience. By continuing to use our website, you are agreeing to our use of cookies. Alternatively, you can manage them in your browser settings.<button style="margin-left:10px" class="CookieMonsterOk" type="button">I understand</button> </div> </div>
Yii 1.1 version
You can find Yii 1.1 version at https://github.com/bizley/Yii-CookieMonster