<?php
namespace aiDESIGNER\ContaoOccupationalSafetyBundle\Modules;
use Contao\CoreBundle\Controller\FrontendModule\AbstractFrontendModuleController;
use Contao\CoreBundle\Exception\RedirectResponseException;
use Contao\CoreBundle\DependencyInjection\Attribute\AsFrontendModule;
use Contao\ModuleModel;
use Contao\PageModel;
use Contao\Template;
use Contao\FrontendUser;
use Contao\FrontendTemplate;
use Contao\System;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Contao\ArticleModel;
use Doctrine\DBAL\Connection;
use Twig\Environment as TwigEnvironment;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Contao\CoreBundle\Routing\ScopeMatcher;
use Symfony\Component\Security\Csrf\CsrfToken;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
/**
* Arbeitsschutz Deutschland User Navigation Module
*
* @author Daniel Richter <daniel@ai-designer.de>
* @copyright aiDESIGNER 2024 <http://www.ai-designer.de>
*/
#[AsFrontendModule(ModLanguageSwitcher::TYPE, category: 'aiDesigner')]
class ModLanguageSwitcher extends AbstractFrontendModuleController
{
public const TYPE = 'mod_language_switcher';
public function __construct(
private Connection $connection,
private TranslatorInterface $translator,
private TwigEnvironment $twig,
private ScopeMatcher $scope,
private UrlGeneratorInterface $generator,
private CsrfTokenManagerInterface $csrfTokenManager
)
{}
protected function getResponse(Template $globalTemplate, ModuleModel $model, Request $request): Response
{
$currentPage = PageModel::findWithDetails($GLOBALS['objPage']->id);
$currentLanguage = $currentPage->urlPrefix;
$globalTemplate->pagename = $currentPage->alias . $currentPage->urlSuffix;
// Sprache in der Session speichern
$GLOBALS['TL_LANGUAGE'] = $currentLanguage;
$globalTemplate->currentLanguage = $currentLanguage;
return new Response( $this->twig->render("@Contao/frontend/mod_language_switcher.html.twig", $globalTemplate->getData()));
}
}