Browse code

Fix wrong clear option handling in getAttributesFromDca hook

Benjamin Roth authored on02/08/2023 11:20:38
Showing1 changed files
... ...
@@ -67,7 +67,7 @@ class GetAttributesFromDca
67 67
             $arrAttributes['class'].= ' ' . $arrAttributes['eSM_fl_class'];
68 68
         }
69 69
 
70
-        if (isset($arrAttributes['eSM_fl_width']))
70
+        if (isset($arrAttributes['eSM_fl_clear']) && $arrAttributes['eSM_fl_clear'])
71 71
         {
72 72
             $arrAttributes['class'].= ' clr';
73 73
         }
... ...
@@ -84,7 +84,6 @@ class GetAttributesFromDca
84 84
                 $arrAttributes['class'].= ' ' . $arrAttributes['eSM_fl_alignment'].'_alignment';
85 85
             }
86 86
         }
87
-
88 87
         return $arrAttributes;
89 88
     }
90 89
 }
Browse code

Reimplement extended registration and personal data form handling

Benjamin Roth authored on22/03/2023 12:59:10
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,90 @@
1
+<?php
2
+
3
+declare(strict_types=1);
4
+
5
+/*
6
+ * This file is part of formilicious bundle for Contao.
7
+ *
8
+ * (c) Benjamin Roth
9
+ *
10
+ * @license LGPL-3.0-or-later
11
+ */
12
+
13
+namespace vonRotenberg\FormiliciousBundle\EventListener;
14
+
15
+use Contao\Controller;
16
+use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
17
+use Contao\DataContainer;
18
+
19
+#[AsHook('getAttributesFromDca')]
20
+class GetAttributesFromDca
21
+{
22
+    public function __invoke(array $arrAttributes, $context): array
23
+    {
24
+        if ($context instanceof DataContainer && $context->field)
25
+        {
26
+            Controller::loadDataContainer($context->table);
27
+            $arrData = $GLOBALS['TL_DCA'][$context->table]['fields'][$context->field];
28
+
29
+            if (isset($arrData['eval']['eSM_fl_width']))
30
+            {
31
+                $arrAttributes['eSM_fl_width'] = $arrData['eval']['eSM_fl_width'];
32
+            }
33
+
34
+            if (isset($arrData['eval']['eSM_fl_clear']))
35
+            {
36
+                $arrAttributes['eSM_fl_clear'] = $arrData['eval']['eSM_fl_clear'];
37
+            }
38
+
39
+            if (isset($arrData['eval']['eSM_fl_class']))
40
+            {
41
+                $arrAttributes['eSM_fl_class'] = $arrData['eval']['eSM_fl_class'];
42
+            }
43
+
44
+            if (isset($arrData['eval']['eSM_fl_lblpadding']))
45
+            {
46
+                $arrAttributes['eSM_fl_lblpadding'] = $arrData['eval']['eSM_fl_lblpadding'];
47
+            }
48
+
49
+            if (isset($arrData['eval']['eSM_fl_alignment']))
50
+            {
51
+                $arrAttributes['eSM_fl_alignment'] = $arrData['eval']['eSM_fl_alignment'];
52
+            }
53
+        }
54
+
55
+        if (!isset($arrAttributes['class']))
56
+        {
57
+            $arrAttributes['class'] = '';
58
+        }
59
+
60
+        if (isset($arrAttributes['eSM_fl_width']) && is_numeric($arrAttributes['eSM_fl_width']))
61
+        {
62
+            $arrAttributes['class'].= ' w' . $arrAttributes['eSM_fl_width'];
63
+        }
64
+
65
+        if (isset($arrAttributes['eSM_fl_class']))
66
+        {
67
+            $arrAttributes['class'].= ' ' . $arrAttributes['eSM_fl_class'];
68
+        }
69
+
70
+        if (isset($arrAttributes['eSM_fl_width']))
71
+        {
72
+            $arrAttributes['class'].= ' clr';
73
+        }
74
+
75
+        if (isset($arrAttributes['type']) && $arrAttributes['type'] === 'submit')
76
+        {
77
+            if (isset($arrAttributes['eSM_fl_lblpadding']))
78
+            {
79
+                $arrAttributes['class'].= ' lblp';
80
+            }
81
+
82
+            if (isset($arrAttributes['eSM_fl_alignment']))
83
+            {
84
+                $arrAttributes['class'].= ' ' . $arrAttributes['eSM_fl_alignment'].'_alignment';
85
+            }
86
+        }
87
+
88
+        return $arrAttributes;
89
+    }
90
+}