<?php
namespace App\Controller;
use App\Entity\Page;
use App\Annotation\CmsComponent;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class ImageTextGridDefaultController extends AbstractController
{
public function __construct(private EntityManagerInterface $em)
{
}
/**
* @CmsComponent("Embed Image Text Grid", active=true, routeName="embed_image_text_grid")
*/
#[Route(path: '/tlb-image-text-grid', name: 'embed_image_text_grid')]
public function embedImageTextGrid(Request $request): Response
{
// get slug and trim initial /
$slug = trim($request->getRequestUri(), '/');
if ($slug === '' || $slug === 'home') {
$page = $this->em->getRepository(Page::class)->findOneBySlugWithGrids(['slug' => 'home']);
} else {
$page = $this->em->getRepository(Page::class)->findOneBySlugWithGrids(['slug' => $slug]);
}
if (!$page) {
return new Response();
}
return $this->render('@theme/image-text-grid/grids.html.twig', [
'grids' => $page->getImageTextGrids(),
]);
}
}