Skip to content

Commit

Permalink
Improving privacy consent methods
Browse files Browse the repository at this point in the history
  • Loading branch information
maper89 committed Jun 28, 2023
1 parent 63c4624 commit f4a21d6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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];
}
}

0 comments on commit f4a21d6

Please sign in to comment.