custom/plugins/EsmCookieConsent/src/Storefront/Subscriber/CookieSubscriber.php line 28

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace EsmCookieConsent\Storefront\Subscriber;
  3. use Shopware\Core\Framework\Struct\ArrayStruct;
  4. use Shopware\Storefront\Framework\Cookie\CookieProviderInterface;
  5. use Shopware\Storefront\Page\GenericPageLoadedEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class CookieSubscriber implements EventSubscriberInterface
  8. {
  9.     private CookieProviderInterface $cookieProvider;
  10.     public function __construct(
  11.         CookieProviderInterface $cookieProvider
  12.     )
  13.     {
  14.         $this->cookieProvider $cookieProvider;
  15.     }
  16.     public static function getSubscribedEvents(): array
  17.     {
  18.         return [
  19.             GenericPageLoadedEvent::class => 'onGenericPageLoaded'
  20.         ];
  21.     }
  22.     public function onGenericPageLoaded(GenericPageLoadedEvent $event): void
  23.     {
  24.         $cookieGroups $this->cookieProvider->getCookieGroups();
  25.         $event->getPage()->addExtension('cookieGroups', new ArrayStruct($cookieGroups));
  26.     }
  27. }