diff --git a/composer/packages/web-toolkit-bundle/src/Resources/config/services.php b/composer/packages/web-toolkit-bundle/src/Resources/config/services.php index d2e714f..1dcd9ca 100644 --- a/composer/packages/web-toolkit-bundle/src/Resources/config/services.php +++ b/composer/packages/web-toolkit-bundle/src/Resources/config/services.php @@ -295,6 +295,7 @@ ; $services->set(WebToolkitBundle::SERVICE_PRIVACY_CONSENT_EXTENSION, PrivacyConsentExtension::class) ->arg(0, new Reference(UrlGeneratorInterface::class)) + ->arg(1, new Reference(RequestStack::class)) ->tag('twig.extension') ; $services->set(WebToolkitBundle::SERVICE_PRIVACY_CREATE_CONSENT_CONTROLLER, CreateConsentController::class) diff --git a/composer/packages/web-toolkit-bundle/src/Twig/PrivacyConsentExtension.php b/composer/packages/web-toolkit-bundle/src/Twig/PrivacyConsentExtension.php index ceaa0ee..328a5c1 100644 --- a/composer/packages/web-toolkit-bundle/src/Twig/PrivacyConsentExtension.php +++ b/composer/packages/web-toolkit-bundle/src/Twig/PrivacyConsentExtension.php @@ -14,6 +14,8 @@ namespace Mep\WebToolkitBundle\Twig; use Mep\WebToolkitBundle\Config\RouteName; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Twig\Extension\AbstractExtension; use Twig\TwigFunction; @@ -58,9 +60,13 @@ class PrivacyConsentExtension extends AbstractExtension */ private const COOKIE_POLICY_ENV_KEY = 'COOKIE_POLICY_URL'; + private readonly ?Request $request; + public function __construct( private readonly UrlGeneratorInterface $urlGenerator, + RequestStack $requestStack, ) { + $this->request = $requestStack->getCurrentRequest(); } /** @@ -116,11 +122,15 @@ public function getPrivacyConsentEndpoint(): array public function getPrivacyPolicyUrl(): string { - return $_ENV[self::PRIVACY_POLICY_ENV_KEY]; + $envKey = self::PRIVACY_POLICY_ENV_KEY.'_'.($this->request?->getLocale() ?? 'NOLANG'); + + return $_ENV[isset($_ENV[$envKey]) ? $envKey : self::PRIVACY_POLICY_ENV_KEY]; } public function getCookiePolicyUrl(): string { - return $_ENV[self::COOKIE_POLICY_ENV_KEY]; + $envKey = self::COOKIE_POLICY_ENV_KEY.'_'.($this->request?->getLocale() ?? 'NOLANG'); + + return $_ENV[isset($_ENV[$envKey]) ? $envKey : self::COOKIE_POLICY_ENV_KEY]; } }