Browse code

Parse insert tags in controllers

Benjamin Roth authored on10/09/2025 10:21:43
Showing1 changed files
... ...
@@ -15,6 +15,7 @@ namespace vonRotenberg\ModalBundle\Controller\FrontendModule;
15 15
 use Contao\ContentModel;
16 16
 use Contao\Controller;
17 17
 use Contao\CoreBundle\Controller\FrontendModule\AbstractFrontendModuleController;
18
+use Contao\CoreBundle\InsertTag\InsertTagParser;
18 19
 use Contao\CoreBundle\ServiceAnnotation\FrontendModule;
19 20
 use Contao\ModuleModel;
20 21
 use Contao\Template;
... ...
@@ -29,6 +30,13 @@ class ModalModuleController extends AbstractFrontendModuleController
29 30
 {
30 31
     public const TYPE = 'modal_module';
31 32
 
33
+    private $insertTagParser;
34
+
35
+    public function __construct(InsertTagParser $insertTagParser)
36
+    {
37
+        $this->insertTagParser = $insertTagParser;
38
+    }
39
+
32 40
     protected function getResponse(Template $template, ModuleModel $model, Request $request): ?Response
33 41
     {
34 42
         if (!$model->modal_configurations || ($modal = ModalModel::findPublishedById($model->modal_configurations)) === null)
... ...
@@ -47,7 +55,7 @@ class ModalModuleController extends AbstractFrontendModuleController
47 55
             {
48 56
                 while ($objElement->next())
49 57
                 {
50
-                    $strDetails .= Controller::getContentElement($objElement->current());
58
+                    $strDetails .= $this->insertTagParser->replace(Controller::getContentElement($objElement->current()));
51 59
                 }
52 60
             }
53 61
 
Browse code

Inject modal code in global TL_BODY instead of returning it inside the page structure

Benjamin Roth authored on11/01/2023 09:31:57
Showing1 changed files
... ...
@@ -61,7 +61,9 @@ class ModalModuleController extends AbstractFrontendModuleController
61 61
 
62 62
         $template->modal_configuration = $modal->row();
63 63
 
64
-        return $template->getResponse();
64
+        $GLOBALS['TL_BODY'][] = $template->parse();
65
+
66
+        return new Response();
65 67
     }
66 68
 
67 69
 }
Browse code

Finalize module and also provide content element

Benjamin Roth authored on10/01/2023 21:52:20
Showing1 changed files
... ...
@@ -12,12 +12,15 @@ declare(strict_types=1);
12 12
 
13 13
 namespace vonRotenberg\ModalBundle\Controller\FrontendModule;
14 14
 
15
+use Contao\ContentModel;
16
+use Contao\Controller;
15 17
 use Contao\CoreBundle\Controller\FrontendModule\AbstractFrontendModuleController;
16 18
 use Contao\CoreBundle\ServiceAnnotation\FrontendModule;
17 19
 use Contao\ModuleModel;
18 20
 use Contao\Template;
19 21
 use Symfony\Component\HttpFoundation\Request;
20 22
 use Symfony\Component\HttpFoundation\Response;
23
+use vonRotenberg\ModalBundle\Model\ModalModel;
21 24
 
22 25
 /**
23 26
  * @FrontendModule(ModalModuleController::TYPE, category="miscellaneous")
... ...
@@ -28,6 +31,36 @@ class ModalModuleController extends AbstractFrontendModuleController
28 31
 
29 32
     protected function getResponse(Template $template, ModuleModel $model, Request $request): ?Response
30 33
     {
34
+        if (!$model->modal_configurations || ($modal = ModalModel::findPublishedById($model->modal_configurations)) === null)
35
+        {
36
+            return new Response();
37
+        }
38
+
39
+        $id = $modal->id;
40
+
41
+        $template->details = function () use ($id)
42
+        {
43
+            $strDetails = '';
44
+            $objElement = ContentModel::findPublishedByPidAndTable($id, 'tl_vr_modal');
45
+
46
+            if ($objElement !== null)
47
+            {
48
+                while ($objElement->next())
49
+                {
50
+                    $strDetails .= Controller::getContentElement($objElement->current());
51
+                }
52
+            }
53
+
54
+            return $strDetails;
55
+        };
56
+
57
+        $template->hasDetails = static function () use ($id)
58
+        {
59
+            return ContentModel::countPublishedByPidAndTable($id, 'tl_vr_modal') > 0;
60
+        };
61
+
62
+        $template->modal_configuration = $modal->row();
63
+
31 64
         return $template->getResponse();
32 65
     }
33 66
 
Browse code

Change directory structure of bundle and add first draft of fragment controller module

Benjamin Roth authored on10/01/2023 14:11:33
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,34 @@
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\FrontendModule;
14
+
15
+use Contao\CoreBundle\Controller\FrontendModule\AbstractFrontendModuleController;
16
+use Contao\CoreBundle\ServiceAnnotation\FrontendModule;
17
+use Contao\ModuleModel;
18
+use Contao\Template;
19
+use Symfony\Component\HttpFoundation\Request;
20
+use Symfony\Component\HttpFoundation\Response;
21
+
22
+/**
23
+ * @FrontendModule(ModalModuleController::TYPE, category="miscellaneous")
24
+ */
25
+class ModalModuleController extends AbstractFrontendModuleController
26
+{
27
+    public const TYPE = 'modal_module';
28
+
29
+    protected function getResponse(Template $template, ModuleModel $model, Request $request): ?Response
30
+    {
31
+        return $template->getResponse();
32
+    }
33
+
34
+}