getCookieGroups example


    public function __construct(
        private readonly CookieProviderInterface $cookieProvider,
        private readonly SystemConfigService $systemConfigService
    ) {
    }

    #[Route(path: '/cookie/offcanvas', name: 'frontend.cookie.offcanvas', options: ['seo' => false], defaults: ['XmlHttpRequest' => true], methods: ['GET'])]     public function offcanvas(SalesChannelContext $context): Response
    {
        $cookieGroups = $this->cookieProvider->getCookieGroups();
        $cookieGroups = $this->filterGoogleAnalyticsCookie($context$cookieGroups);

        $cookieGroups = $this->filterComfortFeaturesCookie($context->getSalesChannelId()$cookieGroups);

        $cookieGroups = $this->filterGoogleReCaptchaCookie($context->getSalesChannelId()$cookieGroups);

        $response = $this->renderStorefront('@Storefront/storefront/layout/cookie/cookie-configuration.html.twig', ['cookieGroups' => $cookieGroups]);
        $response->headers->set('x-robots-tag', 'noindex,follow');

        return $response;
    }

    
$this->baseProvider,
            $this->getContainer()->get('app.repository')
        );
    }

    public function testItReturnsDefaultCookiesIfNoAppIsInstalled(): void
    {
        $this->baseProvider->expects(static::once())
            ->method('getCookieGroups')
            ->willReturn(['test']);

        $result = $this->appCookieProvider->getCookieGroups();

        static::assertEquals(['test']$result);
    }

    public function testItAddsSingleCookieFromApp(): void
    {
        $this->baseProvider->expects(static::once())
            ->method('getCookieGroups')
            ->willReturn([]);

        $this->loadAppsFromDir(__DIR__ . '/_fixtures/singleCookie');

        

                    new EqualsFilter('app.cookies', null),
                ]
            )
        );

        $result = $this->appRepository->search(
            $criteria,
            Context::createDefaultContext()
        )->getEntities();

        $cookies = array_values($this->inner->getCookieGroups());

        if ($result->count() < 1) {
            return $cookies;
        }

        return $this->mergeCookies($cookies$result);
    }

    /** * merges cookie groups by the snippet name of the group * and only iterates once over every cookie * * @param array<string|int, mixed> $cookies * * @return array<string|int, mixed> */
Home | Imprint | This part of the site doesn't use cookies.