<?php declare(strict_types=1); /* * This file is part of modal bundle for Contao. * * (c) Benjamin Roth * * @license LGPL-3.0-or-later */ namespace vonRotenberg\ModalBundle\Controller\ContentElement; use Contao\ContentModel; use Contao\Controller; use Contao\CoreBundle\Controller\ContentElement\AbstractContentElementController; use Contao\CoreBundle\InsertTag\InsertTagParser; use Contao\CoreBundle\ServiceAnnotation\ContentElement; use Contao\CoreBundle\Twig\FragmentTemplate; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use vonRotenberg\ModalBundle\Model\ModalModel; /** * @ContentElement(ModalElementController::TYPE, category="miscellaneous") */ class ModalElementController extends AbstractContentElementController { public const TYPE = 'modal_element'; private $insertTagParser; public function __construct(InsertTagParser $insertTagParser) { $this->insertTagParser = $insertTagParser; } protected function getResponse(FragmentTemplate $template, ContentModel $model, Request $request): Response { if (!$model->modal_configurations || ($modal = ModalModel::findPublishedById($model->modal_configurations)) === null) { return new Response(); } $id = $modal->id; $template->details = function () use ($id) { $strDetails = ''; $objElement = ContentModel::findPublishedByPidAndTable($id, 'tl_vr_modal'); if ($objElement !== null) { while ($objElement->next()) { $strDetails .= $this->insertTagParser->replace(Controller::getContentElement($objElement->current())); } } return $strDetails; }; $template->hasDetails = static function () use ($id) { return ContentModel::countPublishedByPidAndTable($id, 'tl_vr_modal') > 0; }; $template->modal_configuration = $modal->row(); $GLOBALS['TL_BODY'][] = $template->getResponse(); return new Response(); } }