<?php declare(strict_types=1);
namespace EsmCookieConsent\Storefront\Subscriber;
use Shopware\Core\Framework\Struct\ArrayStruct;
use Shopware\Storefront\Framework\Cookie\CookieProviderInterface;
use Shopware\Storefront\Page\GenericPageLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class CookieSubscriber implements EventSubscriberInterface
{
private CookieProviderInterface $cookieProvider;
public function __construct(
CookieProviderInterface $cookieProvider
)
{
$this->cookieProvider = $cookieProvider;
}
public static function getSubscribedEvents(): array
{
return [
GenericPageLoadedEvent::class => 'onGenericPageLoaded'
];
}
public function onGenericPageLoaded(GenericPageLoadedEvent $event): void
{
$cookieGroups = $this->cookieProvider->getCookieGroups();
$event->getPage()->addExtension('cookieGroups', new ArrayStruct($cookieGroups));
}
}