src/Controller/ImageTextGridDefaultController.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Page;
  4. use App\Annotation\CmsComponent;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. class ImageTextGridDefaultController extends AbstractController
  11. {
  12.     public function __construct(private EntityManagerInterface $em)
  13.     {
  14.     }
  15.     /**
  16.      * @CmsComponent("Embed Image Text Grid", active=true, routeName="embed_image_text_grid")
  17.      */
  18.     #[Route(path'/tlb-image-text-grid'name'embed_image_text_grid')]
  19.     public function embedImageTextGrid(Request $request): Response
  20.     {
  21.         // get slug and trim initial /
  22.         $slug trim($request->getRequestUri(), '/');
  23.         if ($slug === '' || $slug === 'home') {
  24.             $page $this->em->getRepository(Page::class)->findOneBySlugWithGrids(['slug' => 'home']);
  25.         } else {
  26.             $page $this->em->getRepository(Page::class)->findOneBySlugWithGrids(['slug' => $slug]);
  27.         }
  28.         if (!$page) {
  29.             return new Response();
  30.         }
  31.         return $this->render('@theme/image-text-grid/grids.html.twig', [
  32.             'grids' => $page->getImageTextGrids(),
  33.         ]);
  34.     }
  35. }