1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* (c) Christian Gripp <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Core23\GDPRBundle\Block\Service; |
13
|
|
|
|
14
|
|
|
use Sonata\AdminBundle\Form\FormMapper; |
15
|
|
|
use Sonata\BlockBundle\Block\BlockContextInterface; |
16
|
|
|
use Sonata\BlockBundle\Block\Service\AbstractAdminBlockService; |
17
|
|
|
use Sonata\BlockBundle\Model\BlockInterface; |
18
|
|
|
use Sonata\CoreBundle\Form\Type\ImmutableArrayType; |
19
|
|
|
use Sonata\CoreBundle\Model\Metadata; |
20
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface; |
21
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
22
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
23
|
|
|
use Symfony\Component\Form\Extension\Core\Type\UrlType; |
24
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
25
|
|
|
use Symfony\Component\HttpFoundation\Response; |
26
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
27
|
|
|
|
28
|
|
|
final class GDPRInformationBlockService extends AbstractAdminBlockService |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var RequestStack |
32
|
|
|
*/ |
33
|
|
|
private $request; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param string $name |
37
|
|
|
* @param EngineInterface $templating |
38
|
|
|
* @param RequestStack $request |
39
|
|
|
*/ |
40
|
|
|
public function __construct(string $name, EngineInterface $templating, RequestStack $request) |
41
|
|
|
{ |
42
|
|
|
parent::__construct($name, $templating); |
43
|
|
|
|
44
|
|
|
$this->request = $request; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
|
|
public function execute(BlockContextInterface $blockContext, Response $response = null) |
51
|
|
|
{ |
52
|
|
|
if ($this->hasGdprCookie()) { |
53
|
|
|
return new Response(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$parameters = [ |
57
|
|
|
'context' => $blockContext, |
58
|
|
|
'settings' => $blockContext->getSettings(), |
59
|
|
|
'block' => $blockContext->getBlock(), |
60
|
|
|
]; |
61
|
|
|
|
62
|
|
|
return $this->renderPrivateResponse($blockContext->getTemplate(), $parameters, $response); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* {@inheritdoc} |
67
|
|
|
*/ |
68
|
|
|
public function buildEditForm(FormMapper $formMapper, BlockInterface $block): void |
69
|
|
|
{ |
70
|
|
|
$formMapper->add('settings', ImmutableArrayType::class, [ |
71
|
|
|
'keys' => [ |
72
|
|
|
['text', TextType::class, [ |
73
|
|
|
'label' => 'form.label_text', |
74
|
|
|
'required' => false, |
75
|
|
|
]], |
76
|
|
|
['url', UrlType::class, [ |
77
|
|
|
'label' => 'form.label_url', |
78
|
|
|
'required' => false, |
79
|
|
|
]], |
80
|
|
|
['position', ChoiceType::class, [ |
81
|
|
|
'label' => 'form.label_position', |
82
|
|
|
'choices' => [ |
83
|
|
|
'form.choice_top' => 'top', |
84
|
|
|
'form.choice_fixedtop' => 'fixedtop', |
85
|
|
|
'form.choice_bottom' => 'bottom', |
86
|
|
|
'form.choice_block' => 'block', |
87
|
|
|
], |
88
|
|
|
]], |
89
|
|
|
], |
90
|
|
|
'translation_domain' => 'Core23GDPRBundle', |
91
|
|
|
]); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* {@inheritdoc} |
96
|
|
|
*/ |
97
|
|
|
public function configureSettings(OptionsResolver $resolver): void |
98
|
|
|
{ |
99
|
|
|
$resolver->setDefaults([ |
100
|
|
|
'text' => null, |
101
|
|
|
'url' => 'https://gdpr-info.eu/', |
102
|
|
|
'template' => '@Core23GDPR/Block/block_gdpr.html.twig', |
103
|
|
|
'position' => 'block', |
104
|
|
|
]); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* {@inheritdoc} |
109
|
|
|
*/ |
110
|
|
|
public function getBlockMetadata($code = null) |
111
|
|
|
{ |
112
|
|
|
return new Metadata($this->getName(), $code ?? $this->getName(), false, 'Core23GDPRBundle', [ |
113
|
|
|
'class' => 'fa fa-balance-scale', |
114
|
|
|
]); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return bool |
119
|
|
|
*/ |
120
|
|
|
private function hasGdprCookie(): bool |
121
|
|
|
{ |
122
|
|
|
$request = $this->request->getMasterRequest(); |
123
|
|
|
|
124
|
|
|
return $request && $request->cookies->getBoolean('GDPR_COOKIE_LAW_CONSENT', false); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|