├── widgets ├── views │ └── cookieWidget.php └── CookieWidget.php ├── composer.json ├── assets └── CookieAsset.php └── README.md /widgets/views/cookieWidget.php: -------------------------------------------------------------------------------- 1 | assetBundles[CookieAsset::class]; 19 | 20 | // Create codeJS 21 | $codeJS = "window.cookieconsent_options = { message: '{$message}', dismiss: '{$dismiss}', learnMore: '{$learnMore}', link: '{$link}', theme: '{$theme}', container: '{$container}', path: '{$path}',"; 22 | 23 | if($domain){ 24 | $codeJS .= " domain: '{$domain}',"; 25 | } 26 | 27 | $codeJS .= " expiryDays: {$expiryDays} };"; 28 | 29 | $this->registerJs($codeJS, \yii\web\View::POS_END); 30 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cinghie/yii2-cookie-consent", 3 | "description": "Yii2 Cookie Consent to alerting users about the use of cookies on your Yii2 website.", 4 | "keywords": [ 5 | "yii2", 6 | "yii2 cookie", 7 | "yii2 cookie law", 8 | "yii2 cookie consent", 9 | "yii2 eu cookie consent" 10 | ], 11 | "homepage": "https://github.com/cinghie/yii2-cookie-consent", 12 | "type": "yii2-extension", 13 | "license": "BSD-3-Clause", 14 | "authors": [ 15 | { 16 | "name": "Gogodigital.it", 17 | "email": "info@gogodigital.it", 18 | "homepage": "http://www.gogodigital.it/" 19 | } 20 | ], 21 | "require": { 22 | "yiisoft/yii2": "^2.0.14", 23 | "bower-asset/cookieconsent": "^3.1.1" 24 | }, 25 | "autoload": { 26 | "psr-4": { 27 | "cinghie\\cookieconsent\\": "" 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /assets/CookieAsset.php: -------------------------------------------------------------------------------- 1 | 'This website uses cookies to ensure you get the best experience on our website.', 39 | 'dismiss' => 'Got It', 40 | 'learnMore' => 'More info', 41 | 'link' => 'http://silktide.com/privacy-policy', 42 | 'theme' => 'dark-bottom' 43 | ]); ?> 44 | ``` 45 | 46 | Theme Options 47 | ----------------- 48 | 49 | 53 | -------------------------------------------------------------------------------- /widgets/CookieWidget.php: -------------------------------------------------------------------------------- 1 | message) { 38 | $this->message = 'This website uses cookies to ensure you get the best experience on our website.'; 39 | } 40 | 41 | if(!$this->dismiss) { 42 | $this->dismiss = 'Got It!'; 43 | } 44 | 45 | if(!$this->learnMore) { 46 | $this->learnMore = 'More info'; 47 | } 48 | 49 | if(!$this->link) { 50 | $this->link = null; 51 | } 52 | 53 | if(!$this->theme) { 54 | $this->theme = 'dark-bottom'; 55 | } 56 | 57 | if(!$this->container) { 58 | $this->container = null; 59 | } 60 | 61 | if(!$this->path) { 62 | $this->path = '/'; 63 | } 64 | 65 | if(!$this->domain) { 66 | $this->domain = ''; 67 | } 68 | 69 | if(!$this->expiryDays) { 70 | $this->expiryDays = '365'; 71 | } 72 | } 73 | 74 | /** 75 | * @param array $params 76 | * 77 | * @return string 78 | */ 79 | public function run($params = []) 80 | { 81 | return $this->render('cookieWidget',[ 82 | 'message' => $this->message, 83 | 'dismiss' => $this->dismiss, 84 | 'learnMore' => $this->learnMore, 85 | 'link' => $this->link, 86 | 'theme' => $this->theme, 87 | 'container' => $this->container, 88 | 'path' => $this->path, 89 | 'domain' => $this->domain, 90 | 'expiryDays' => $this->expiryDays 91 | ]); 92 | } 93 | 94 | } 95 | --------------------------------------------------------------------------------