Browse code

Add js template hint in module and content element

Benjamin Roth authored on12/01/2023 14:38:34
Showing2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,56 @@
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\EventListener\DataContainer;
14
+
15
+use Contao\ContentModel;
16
+use Contao\CoreBundle\Security\ContaoCorePermissions;
17
+use Contao\CoreBundle\ServiceAnnotation\Callback;
18
+use Contao\DataContainer;
19
+use Contao\Input;
20
+use Contao\Message;
21
+use Contao\System;
22
+use vonRotenberg\ModalBundle\Controller\ContentElement\ModalElementController;
23
+
24
+class ContentDataContainerListener
25
+{
26
+    /**
27
+     * @Callback(table="tl_content", target="config.onload")
28
+     */
29
+    public function showJsHints(DataContainer $dc = null)
30
+    {
31
+        if ($_POST || Input::get('act') != 'edit')
32
+        {
33
+            return;
34
+        }
35
+
36
+        $security = System::getContainer()->get('security.helper');
37
+
38
+        // Return if the user cannot access the layout module (see #6190)
39
+        if (!$security->isGranted(ContaoCorePermissions::USER_CAN_ACCESS_MODULE, 'themes') || !$security->isGranted(ContaoCorePermissions::USER_CAN_ACCESS_LAYOUTS))
40
+        {
41
+            return;
42
+        }
43
+
44
+        $objCte = ContentModel::findByPk($dc->id);
45
+
46
+        if ($objCte === null)
47
+        {
48
+            return;
49
+        }
50
+
51
+        if ($objCte->type == ModalElementController::TYPE)
52
+        {
53
+            Message::addInfo(sprintf($GLOBALS['TL_LANG']['tl_content']['includeTemplate'], 'j_jbox'));
54
+        }
55
+    }
56
+}
0 57
new file mode 100644
... ...
@@ -0,0 +1,56 @@
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\EventListener\DataContainer;
14
+
15
+use Contao\CoreBundle\Security\ContaoCorePermissions;
16
+use Contao\CoreBundle\ServiceAnnotation\Callback;
17
+use Contao\DataContainer;
18
+use Contao\Input;
19
+use Contao\Message;
20
+use Contao\ModuleModel;
21
+use Contao\System;
22
+use vonRotenberg\ModalBundle\Controller\FrontendModule\ModalModuleController;
23
+
24
+class ModuleDataContainerListener
25
+{
26
+    /**
27
+     * @Callback(table="tl_module", target="config.onload")
28
+     */
29
+    public function showJsHints(DataContainer $dc = null)
30
+    {
31
+        if ($_POST || Input::get('act') != 'edit')
32
+        {
33
+            return;
34
+        }
35
+
36
+        $security = System::getContainer()->get('security.helper');
37
+
38
+        // Return if the user cannot access the layout module (see #6190)
39
+        if (!$security->isGranted(ContaoCorePermissions::USER_CAN_ACCESS_MODULE, 'themes') || !$security->isGranted(ContaoCorePermissions::USER_CAN_ACCESS_LAYOUTS))
40
+        {
41
+            return;
42
+        }
43
+
44
+        $objModule = ModuleModel::findByPk($dc->id);
45
+
46
+        if ($objModule === null)
47
+        {
48
+            return;
49
+        }
50
+
51
+        if ($objModule->type == ModalModuleController::TYPE)
52
+        {
53
+            Message::addInfo(sprintf($GLOBALS['TL_LANG']['tl_content']['includeTemplate'], 'j_jbox'));
54
+        }
55
+    }
56
+}