__aiDESIGNER/contao-occupational-safety/src/Modules/ModLanguageSwitcher.php line 32

Open in your IDE?
  1. <?php
  2. namespace aiDESIGNER\ContaoOccupationalSafetyBundle\Modules;
  3. use Contao\CoreBundle\Controller\FrontendModule\AbstractFrontendModuleController;
  4. use Contao\CoreBundle\Exception\RedirectResponseException;
  5. use Contao\CoreBundle\DependencyInjection\Attribute\AsFrontendModule;
  6. use Contao\ModuleModel;
  7. use Contao\PageModel;
  8. use Contao\Template;
  9. use Contao\FrontendUser;
  10. use Contao\FrontendTemplate;
  11. use Contao\System;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Contao\ArticleModel;
  15. use Doctrine\DBAL\Connection;
  16. use Twig\Environment as TwigEnvironment;
  17. use Symfony\Contracts\Translation\TranslatorInterface;
  18. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  19. use Contao\CoreBundle\Routing\ScopeMatcher;
  20. use Symfony\Component\Security\Csrf\CsrfToken;
  21. use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
  22. /**
  23.  * Arbeitsschutz Deutschland User Navigation Module
  24.  * 
  25.  * @author Daniel Richter <daniel@ai-designer.de>
  26.  * @copyright aiDESIGNER 2024 <http://www.ai-designer.de>
  27.  */
  28. #[AsFrontendModule(ModLanguageSwitcher::TYPEcategory'aiDesigner')]
  29. class ModLanguageSwitcher extends AbstractFrontendModuleController
  30. {
  31.     public const TYPE 'mod_language_switcher';
  32.     public function __construct(
  33.         private Connection $connection
  34.         private TranslatorInterface $translator,
  35.         private TwigEnvironment $twig,
  36.         private ScopeMatcher $scope,
  37.         private UrlGeneratorInterface $generator,
  38.         private CsrfTokenManagerInterface $csrfTokenManager
  39.     )
  40.     {}
  41.     protected function getResponse(Template $globalTemplateModuleModel $modelRequest $request): Response
  42.     {
  43.         $currentPage PageModel::findWithDetails($GLOBALS['objPage']->id);
  44.         
  45.         $currentLanguage $currentPage->urlPrefix;
  46.         $globalTemplate->pagename $currentPage->alias $currentPage->urlSuffix;
  47.         // Sprache in der Session speichern
  48.         $GLOBALS['TL_LANGUAGE'] = $currentLanguage;
  49.         $globalTemplate->currentLanguage $currentLanguage;
  50.         return new Response$this->twig->render("@Contao/frontend/mod_language_switcher.html.twig"$globalTemplate->getData()));
  51.         
  52.     }
  53. }