<?php
namespace App\Controller\Front;
use Stimactiv\CmsBundle\Repository\PageI18nRepository;
use Stimactiv\CoreBundle\Repository\LangRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/", name="frontend_")
*/
class MainController extends AbstractController implements AgeVerificationControllerInterface
{
/**
* @Route("/", name="home", methods={"GET"})
*/
public function index(Request $request, LangRepository $langRepository, PageI18nRepository $pageI18nRepository): Response
{
$lang = $langRepository->findOneBy(['code' => $request->getLocale()]);
if ($lang === null) {
$lang = $langRepository->findOneBy(['byDefault' => true]);
}
$page_id = 1; // TODO
$pageI18n = $pageI18nRepository->findOneBy(['page' => $page_id, 'lang' => $lang]);
if ($pageI18n === null) {
throw $this->createNotFoundException();
}
return $this->redirectToRoute('frontend_page_show', ['slug' => $pageI18n->getSlug()]);
}
}