... | ... |
@@ -15,6 +15,7 @@ namespace vonRotenberg\ModalBundle\Controller\ContentElement; |
15 | 15 |
use Contao\ContentModel; |
16 | 16 |
use Contao\Controller; |
17 | 17 |
use Contao\CoreBundle\Controller\ContentElement\AbstractContentElementController; |
18 |
+use Contao\CoreBundle\InsertTag\InsertTagParser; |
|
18 | 19 |
use Contao\CoreBundle\ServiceAnnotation\ContentElement; |
19 | 20 |
use Contao\Template; |
20 | 21 |
use Symfony\Component\HttpFoundation\Request; |
... | ... |
@@ -28,6 +29,13 @@ class ModalElementController extends AbstractContentElementController |
28 | 29 |
{ |
29 | 30 |
public const TYPE = 'modal_element'; |
30 | 31 |
|
32 |
+ private $insertTagParser; |
|
33 |
+ |
|
34 |
+ public function __construct(InsertTagParser $insertTagParser) |
|
35 |
+ { |
|
36 |
+ $this->insertTagParser = $insertTagParser; |
|
37 |
+ } |
|
38 |
+ |
|
31 | 39 |
protected function getResponse(Template $template, ContentModel $model, Request $request): ?Response |
32 | 40 |
{ |
33 | 41 |
if (!$model->modal_configurations || ($modal = ModalModel::findPublishedById($model->modal_configurations)) === null) |
... | ... |
@@ -46,7 +54,7 @@ class ModalElementController extends AbstractContentElementController |
46 | 54 |
{ |
47 | 55 |
while ($objElement->next()) |
48 | 56 |
{ |
49 |
- $strDetails .= Controller::getContentElement($objElement->current()); |
|
57 |
+ $strDetails .= $this->insertTagParser->replace(Controller::getContentElement($objElement->current())); |
|
50 | 58 |
} |
51 | 59 |
} |
52 | 60 |
|
... | ... |
@@ -60,7 +60,9 @@ class ModalElementController extends AbstractContentElementController |
60 | 60 |
|
61 | 61 |
$template->modal_configuration = $modal->row(); |
62 | 62 |
|
63 |
- return $template->getResponse(); |
|
63 |
+ $GLOBALS['TL_BODY'][] = $template->parse(); |
|
64 |
+ |
|
65 |
+ return new Response(); |
|
64 | 66 |
} |
65 | 67 |
|
66 | 68 |
} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,66 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+declare(strict_types=1); |
|
4 |
+ |
|
5 |
+/* |
|
6 |
+ * This file is part of modal bundle for Contao. |
|
7 |
+ * |
|
8 |
+ * (c) Benjamin Roth |
|
9 |
+ * |
|
10 |
+ * @license LGPL-3.0-or-later |
|
11 |
+ */ |
|
12 |
+ |
|
13 |
+namespace vonRotenberg\ModalBundle\Controller\ContentElement; |
|
14 |
+ |
|
15 |
+use Contao\ContentModel; |
|
16 |
+use Contao\Controller; |
|
17 |
+use Contao\CoreBundle\Controller\ContentElement\AbstractContentElementController; |
|
18 |
+use Contao\CoreBundle\ServiceAnnotation\ContentElement; |
|
19 |
+use Contao\Template; |
|
20 |
+use Symfony\Component\HttpFoundation\Request; |
|
21 |
+use Symfony\Component\HttpFoundation\Response; |
|
22 |
+use vonRotenberg\ModalBundle\Model\ModalModel; |
|
23 |
+ |
|
24 |
+/** |
|
25 |
+ * @ContentElement(ModalElementController::TYPE, category="miscellaneous") |
|
26 |
+ */ |
|
27 |
+class ModalElementController extends AbstractContentElementController |
|
28 |
+{ |
|
29 |
+ public const TYPE = 'modal_element'; |
|
30 |
+ |
|
31 |
+ protected function getResponse(Template $template, ContentModel $model, Request $request): ?Response |
|
32 |
+ { |
|
33 |
+ if (!$model->modal_configurations || ($modal = ModalModel::findPublishedById($model->modal_configurations)) === null) |
|
34 |
+ { |
|
35 |
+ return new Response(); |
|
36 |
+ } |
|
37 |
+ |
|
38 |
+ $id = $modal->id; |
|
39 |
+ |
|
40 |
+ $template->details = function () use ($id) |
|
41 |
+ { |
|
42 |
+ $strDetails = ''; |
|
43 |
+ $objElement = ContentModel::findPublishedByPidAndTable($id, 'tl_vr_modal'); |
|
44 |
+ |
|
45 |
+ if ($objElement !== null) |
|
46 |
+ { |
|
47 |
+ while ($objElement->next()) |
|
48 |
+ { |
|
49 |
+ $strDetails .= Controller::getContentElement($objElement->current()); |
|
50 |
+ } |
|
51 |
+ } |
|
52 |
+ |
|
53 |
+ return $strDetails; |
|
54 |
+ }; |
|
55 |
+ |
|
56 |
+ $template->hasDetails = static function () use ($id) |
|
57 |
+ { |
|
58 |
+ return ContentModel::countPublishedByPidAndTable($id, 'tl_vr_modal') > 0; |
|
59 |
+ }; |
|
60 |
+ |
|
61 |
+ $template->modal_configuration = $modal->row(); |
|
62 |
+ |
|
63 |
+ return $template->getResponse(); |
|
64 |
+ } |
|
65 |
+ |
|
66 |
+} |