|
|
@@ -0,0 +1,64 @@ |
|
|
|
<?php |
|
|
|
|
|
|
|
namespace Lc\ShopBundle\Form\Frontend; |
|
|
|
|
|
|
|
use ConnectHolland\CookieConsentBundle\Cookie\CookieChecker; |
|
|
|
use Symfony\Component\Form\AbstractType; |
|
|
|
use Symfony\Component\Form\AbstractTypeExtension; |
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; |
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
|
|
|
use ConnectHolland\CookieConsentBundle\Form\CookieConsentType as BaseCookieConsentType ; |
|
|
|
|
|
|
|
class CookieConsentTypeExtension extends AbstractTypeExtension |
|
|
|
{ |
|
|
|
/** |
|
|
|
* @var CookieChecker |
|
|
|
*/ |
|
|
|
protected $cookieChecker; |
|
|
|
|
|
|
|
/** |
|
|
|
* @var array |
|
|
|
*/ |
|
|
|
protected $cookieCategories; |
|
|
|
|
|
|
|
/** |
|
|
|
* @var bool |
|
|
|
*/ |
|
|
|
protected $cookieConsentSimplified; |
|
|
|
|
|
|
|
public function __construct(CookieChecker $cookieChecker, array $cookieCategories = [], bool $cookieConsentSimplified = false) |
|
|
|
{ |
|
|
|
$this->cookieChecker = $cookieChecker; |
|
|
|
$this->cookieCategories = $cookieCategories; |
|
|
|
$this->cookieConsentSimplified = $cookieConsentSimplified; |
|
|
|
} |
|
|
|
|
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options): void |
|
|
|
{ |
|
|
|
foreach ($this->cookieCategories as $category) { |
|
|
|
$builder->remove($category) ; |
|
|
|
|
|
|
|
$data = 'true' ; |
|
|
|
if($this->cookieChecker->isCookieConsentSavedByUser() && !$this->cookieChecker->isCategoryAllowedByUser($category)) { |
|
|
|
$data = 'false' ; |
|
|
|
} |
|
|
|
|
|
|
|
$builder->add($category, ChoiceType::class, [ |
|
|
|
'expanded' => true, |
|
|
|
'multiple' => false, |
|
|
|
'data' => $data, |
|
|
|
'choices' => [ |
|
|
|
['ch_cookie_consent.yes' => 'true'], |
|
|
|
['ch_cookie_consent.no' => 'false'], |
|
|
|
], |
|
|
|
]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static function getExtendedTypes(): iterable |
|
|
|
{ |
|
|
|
return [BaseCookieConsentType::class]; |
|
|
|
} |
|
|
|
} |