1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Tag Manager |
4
|
|
|
* Copyright (c) Webmatch GmbH |
5
|
|
|
* |
6
|
|
|
* This program is free software: you can redistribute it and/or modify |
7
|
|
|
* it under the terms of the GNU General Public License as published by |
8
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
9
|
|
|
* (at your option) any later version. |
10
|
|
|
* |
11
|
|
|
* This program is distributed in the hope that it will be useful, |
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
* GNU General Public License for more details. |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace WbmTagManager\Subscriber\Frontend; |
18
|
|
|
|
19
|
|
|
use Enlight\Event\SubscriberInterface; |
20
|
|
|
use Enlight_Components_Snippet_Manager; |
21
|
|
|
use Enlight_Controller_ActionEventArgs; |
22
|
|
|
use Shopware\Bundle\CookieBundle\CookieCollection; |
23
|
|
|
use Shopware\Bundle\CookieBundle\Structs\CookieGroupStruct; |
24
|
|
|
use Shopware\Bundle\CookieBundle\Structs\CookieStruct; |
25
|
|
|
use Shopware_Components_Config; |
26
|
|
|
|
27
|
|
|
class CookieConsent extends ConfigAbstract implements SubscriberInterface |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var Enlight_Components_Snippet_Manager |
31
|
|
|
*/ |
32
|
|
|
private $snippets; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
private $pluginDir; |
38
|
|
|
|
39
|
|
|
public function __construct(Shopware_Components_Config $config, Enlight_Components_Snippet_Manager $snippets, $pluginDir) |
40
|
|
|
{ |
41
|
|
|
$this->snippets = $snippets; |
42
|
|
|
$this->pluginDir = $pluginDir; |
43
|
|
|
parent::__construct($config); |
44
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public static function getSubscribedEvents(): array |
48
|
|
|
{ |
49
|
|
|
return [ |
50
|
|
|
'CookieCollector_Collect_Cookies' => 'addCookie', |
51
|
|
|
'Enlight_Controller_Action_PreDispatch' => 'onPreDispatch' |
52
|
|
|
]; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function onPreDispatch(Enlight_Controller_ActionEventArgs $args) |
56
|
|
|
{ |
57
|
|
|
$args->getSubject()->View()->addTemplateDir($this->pluginDir . '/Resources/views'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function addCookie(): CookieCollection |
61
|
|
|
{ |
62
|
|
|
$collection = new CookieCollection(); |
63
|
|
|
|
64
|
|
|
if (!$this->pluginConfig('wbmTagManagerCookieConsent')) { |
65
|
|
|
return $collection; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$pluginNamespace = $this->snippets->getNamespace('frontend/wbm_tag_manager/cookie'); |
69
|
|
|
|
70
|
|
|
$collection->add(new CookieStruct( |
71
|
|
|
'wbm_tag_manager', |
72
|
|
|
'/^wbm_tag_manager/', |
73
|
|
|
$pluginNamespace->get('label'), |
74
|
|
|
CookieGroupStruct::STATISTICS |
75
|
|
|
)); |
76
|
|
|
|
77
|
|
|
return $collection; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|