src/Controller/DefaultController.php line 40
<?phpnamespace App\Controller;use App\Controller\Traits\HreflangsControllerTrait;use App\Controller\Traits\MetatagsControllerTrait;use App\Controller\Traits\StaticPageHelperTrait;use App\Entity\Magazine;use App\Entity\PrivacyPolicy;use App\Entity\ProductCategory;use App\Entity\ProductType;use App\Entity\Recipe;use App\Entity\StaticPage;use App\Repository\MagazineRepository;use App\Repository\RecipeRepository;use Doctrine\ORM\EntityManagerInterface;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\HttpFoundation\RedirectResponse;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\Routing\Annotation\Route;use Symfony\Component\Routing\Generator\UrlGeneratorInterface;use Symfony\Contracts\Translation\TranslatorInterface;class DefaultController extends AbstractController{use MetatagsControllerTrait, HreflangsControllerTrait, StaticPageHelperTrait;private $em;private $transalor;public function __construct(EntityManagerInterface $em, TranslatorInterface $translator){$this->em = $em;$this->transalor = $translator;}#[Route(['/','en' => '/en',// 'es' => '/es','de' => '/de',], name: 'homepage')]public function homepage(Request $request, EntityManagerInterface $em){$host = $request->getHost();if($host == $this->getParameter('de_host')){return $this->forward('App\Controller\LandingController::landingVerdeAmore', ['_route' => $request->get('_route')]);}if ($request->getLocale() == 'de') {// TODO RIATTIVA PER DE// if ($host == $this->getParameter('base_host')) {$scheme = $request->getScheme(); // http o https$redirectUrl = $scheme . '://' . $this->getParameter('de_host').'/de';return new RedirectResponse($redirectUrl, 301); // redirect permanente.'/de'// }}list ($metatags, $hreflangs) = $this->getStaticPageMetatagsAndHreflangs($request, $em, $this->getParameter('locales'));/** @var MagazineRepository $magazineRepository */$magazineRepository = $this->em->getRepository(Magazine::class);$magazine = $magazineRepository->findOneBy(['type' => 'MAGAZINE','isEnabled' => true,'locale' => $request->getLocale()],[// 'id' => 'DESC''sortablePosition' => 'DESC',]);/** @var RecipeRepository $recipeRepository */$recipeRepository = $this->em->getRepository(Recipe::class);$recipe = $recipeRepository->findOneBy(['isEnabled' => true,'isInHome' => true,'locale' => $request->getLocale()],['id' => 'DESC']);$productCategories = $this->em->getRepository(ProductCategory::class)->findBy(['locale' => $request->getLocale(),'enabled' => 1,'parent' => null],['sortablePosition' => 'ASC']);$productTypes = $this->em->getRepository(ProductType::class)->findBy(['enabled' => true,'locale' => $request->getLocale()],['sortablePosition' => 'ASC']);// foreach ($productTypes as $key => $pT){// if ($pT->getName() == 'Spalmabile'){// unset($productTypes[$key]);// }// }$template = 'default/index.html.twig';if ($request->getLocale() == 'it') {$template = 'default/index_it.html.twig';}return $this->render($template, ['magazine' => $magazine,'recipe' => $recipe,'productCategories' => $productCategories,'productTypes' => $productTypes,'metatags' => $metatags,'hreflangs' => $hreflangs]);}public function headerAction(Request $request, string $route = null){$productCategories = $this->em->getRepository(ProductCategory::class)->findBy(['locale' => $request->getLocale(),'enabled' => 1,'parent' => null],['sortablePosition' => 'ASC']);$productTypes = $this->em->getRepository(ProductType::class)->findBy(['enabled' => true,'locale' => $request->getLocale()],['sortablePosition' => 'ASC']);return $this->render('partials/layout/_header.html.twig', ['productCategories' => $productCategories,'current_route' => $route,'productTypes' => $productTypes,]);}public function footerAction(Request $request, $banner, $color, $currentPath = null){$productCategories = $this->em->getRepository(ProductCategory::class)->findBy(['locale' => $request->getLocale(),'enabled' => 1,'parent' => null],['sortablePosition' => 'ASC']);if ($currentPath != 'homepage'){$currentPath = NULL;}return $this->render('partials/layout/_footer.html.twig', ['productCategories' => $productCategories,'banner' => $banner,'color' => $color,'currentPath' => $currentPath]);}}