src/Modules/VoucherCart/Controller/LocaleController.php line 43
<?phpnamespace App\Modules\VoucherCart\Controller;use Symfony\Component\HttpFoundation\Response;use Doctrine\Persistence\ManagerRegistry;use App\Service\LocaleService;use App\Modules\User\Service\UserService;class LocaleController extends BaseController{private $_doctrine;private $_localeService;private $_userService;public function __construct(ManagerRegistry $doctrine,LocaleService $localeService,UserService $userService){$this->_doctrine = $doctrine;$this->_localeService = $localeService;$this->_userService = $userService;}public function changeLocale($locale){$this->_localeService->setLocale($locale);$locale = $this->_localeService->getLocale();$user = $this->_userService->getLoggedUser(false);if ($user && $user->getSelectedLang() != $locale){$user->setSelectedLang($locale);$em = $this->_doctrine->getManager();$em->persist($user);$em->flush();}return $this->returnToPreviousPage();}public function languageWidget($route = null){$selectedLocale = $this->_localeService->getLocale();$locales = array();foreach($this->_localeService->getAvailableLocales() as $locale)$locales[$locale] = $this->_localeService->getLocaleName($locale);if (count($locales) <= 1)return new Response();return $this->render($view ?? 'Modules/VoucherCart/Templates/Locale/languageWidget.html.twig', array('locales' => $locales,'selectedLocale' => $selectedLocale,'route' => $route ?? 'change_locale'));}}