<?php
declare(strict_types=1);
namespace BitBag\OpenMarketplace\Component\Locale\Controller;
use Sylius\Bundle\ShopBundle\Controller\LocaleSwitchController as BaseLocaleSwitchController;
use Sylius\Component\Locale\Context\LocaleContextInterface;
use Sylius\Component\Locale\Provider\LocaleProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Templating\EngineInterface;
use Twig\Environment;
final class LocaleSwitcherController
{
public function __construct(
private EngineInterface|Environment $templatingEngine,
private LocaleContextInterface $localeContext,
private LocaleProviderInterface $localeProvider,
private BaseLocaleSwitchController $baseLocaleSwitchController,
private RequestStack $requestStack
) {
}
public function renderAction(): Response
{
$mainRequest = $this->requestStack->getMainRequest();
return new Response($this->templatingEngine->render('@SyliusShop/Menu/_localeSwitch.html.twig', [
'active' => $this->localeContext->getLocaleCode(),
'locales' => $this->localeProvider->getAvailableLocalesCodes(),
'mainRequest' => $mainRequest,
]));
}
public function switchAction(Request $request, ?string $code = null): Response
{
return $this->baseLocaleSwitchController->switchAction($request, $code);
}
}