<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use App\Service\EditeurManager;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class EditeurController extends AbstractController
{
/**
* @Route("/{label}", name="page_statique", requirements={"label" = "^((?!js\/routing|.jpeg|.ico|.png|.webp|.jpg|.pdf|.js|.css).)*$"}, options={"expose"=true})
* @Route("/", name="home", options={"expose"=true})
*/
public function index(EditeurManager $editeurManager, Request $request, $label = '/') : Response
{
$locale = $request->getLocale();
$label = str_replace('/'.$locale.'/', '/', $label);
// // Redirige la route avec une locale (Pour les traductions)
// if ($request->attributes->get('_locale') == '') {
// return $this->redirect('/'.$locale.$request->getPathInfo());
// }
if($label == '/' || $label == '') {
$label = 'home';
}
$label = trim(str_replace('/', '-', $label), '-');
$pageName = "{$label}.html.twig";
$filePath = "editeur/pages/{$pageName}";
$data = $editeurManager->getPageData($filePath, $pageName, $request);
return $this->render($filePath, $data);
}
/**
* @Route("/partial-blocks/{block}", name="partial_blocks", priority=1)
*/
public function blocksInclude(Request $request, $block, EditeurManager $editeurManager)
{
$data = $editeurManager->getBlockData($block, $request);
return $this->render('editeur/includes/block.html.twig',
array_merge(
[
'block_path' => "editeur/includes/blocks/{$block}.html.twig"
],
$data
)
);
}
/**
* @Route("/page-include/{name}", name="page_include", priority=1)
*/
public function pageInclude(Request $request, $name, EditeurManager $editeurManager)
{
$tab = ['header', 'footer'];
$data = [];
if (in_array($name, $tab)) {
return $this->render('editeur/includes/block.html.twig',
array_merge(
[
'block_path' => "includes/{$name}.html.twig"
],
$data
)
);
} else {
throw new \Exception('No access !!', 1);
}
}
}