src/Controller/EditeurController.php line 37

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use App\Service\EditeurManager;
  8. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  9. class EditeurController extends AbstractController
  10. {
  11.    /**
  12.     * @Route("/{label}", name="page_statique", requirements={"label" = "^((?!js\/routing|.jpeg|.ico|.png|.webp|.jpg|.pdf|.js|.css).)*$"}, options={"expose"=true})
  13.     * @Route("/", name="home", options={"expose"=true})
  14.     */
  15.     public function index(EditeurManager $editeurManagerRequest $request$label '/') : Response
  16.     {
  17.         $locale $request->getLocale();
  18.         $label str_replace('/'.$locale.'/''/'$label);
  19.         // // Redirige la route avec une locale (Pour les traductions)
  20.         // if ($request->attributes->get('_locale') == '') {
  21.         //     return $this->redirect('/'.$locale.$request->getPathInfo());
  22.         // }
  23.         if($label == '/' || $label == '') {
  24.             $label 'home';
  25.         }
  26.         $label trim(str_replace('/''-'$label), '-');
  27.         
  28.         $pageName "{$label}.html.twig";
  29.         $filePath "editeur/pages/{$pageName}";
  30.         $data $editeurManager->getPageData($filePath$pageName$request);
  31.         
  32.         return $this->render($filePath$data);
  33.     }
  34.     /**
  35.     * @Route("/partial-blocks/{block}", name="partial_blocks", priority=1)
  36.     */
  37.     public function blocksInclude(Request $request$blockEditeurManager $editeurManager)
  38.     {
  39.         
  40.         $data $editeurManager->getBlockData($block$request);
  41.         
  42.         return $this->render('editeur/includes/block.html.twig'
  43.             array_merge(
  44.                 [
  45.                     'block_path' => "editeur/includes/blocks/{$block}.html.twig"
  46.                 ], 
  47.                 $data
  48.             )
  49.         );
  50.     }
  51.     /**
  52.     * @Route("/page-include/{name}", name="page_include", priority=1)
  53.     */
  54.     public function pageInclude(Request $request$nameEditeurManager $editeurManager)
  55.     {
  56.         $tab = ['header''footer'];
  57.         $data = [];
  58.         
  59.         if (in_array($name$tab)) {
  60.             return $this->render('editeur/includes/block.html.twig'
  61.                 array_merge(
  62.                     [
  63.                         'block_path' => "includes/{$name}.html.twig"
  64.                     ], 
  65.                     $data
  66.                 )
  67.             );
  68.         } else {
  69.             throw new \Exception('No access !!'1);
  70.             
  71.         }
  72.     }
  73. }