src/Component/Locale/Controller/LocaleSwitcherController.php line 27

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace BitBag\OpenMarketplace\Component\Locale\Controller;
  4. use Sylius\Bundle\ShopBundle\Controller\LocaleSwitchController as BaseLocaleSwitchController;
  5. use Sylius\Component\Locale\Context\LocaleContextInterface;
  6. use Sylius\Component\Locale\Provider\LocaleProviderInterface;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\RequestStack;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Templating\EngineInterface;
  11. use Twig\Environment;
  12. final class LocaleSwitcherController
  13. {
  14.     public function __construct(
  15.         private EngineInterface|Environment $templatingEngine,
  16.         private LocaleContextInterface $localeContext,
  17.         private LocaleProviderInterface $localeProvider,
  18.         private BaseLocaleSwitchController $baseLocaleSwitchController,
  19.         private RequestStack $requestStack
  20.     ) {
  21.     }
  22.     public function renderAction(): Response
  23.     {
  24.         $mainRequest $this->requestStack->getMainRequest();
  25.         return new Response($this->templatingEngine->render('@SyliusShop/Menu/_localeSwitch.html.twig', [
  26.             'active' => $this->localeContext->getLocaleCode(),
  27.             'locales' => $this->localeProvider->getAvailableLocalesCodes(),
  28.             'mainRequest' => $mainRequest,
  29.         ]));
  30.     }
  31.     public function switchAction(Request $request, ?string $code null): Response
  32.     {
  33.         return $this->baseLocaleSwitchController->switchAction($request$code);
  34.     }
  35. }