Browse code

Use getAttributesFromDca hook instead of overwriting Contao core class

(cherry picked from commit 0f1d81fc8c59a778791fe30389211351871a8bc6)

Benjamin Roth authored on07/10/2019 12:10:12
Showing4 changed files
1 1
deleted file mode 100644
... ...
@@ -1,68 +0,0 @@
1
-<?php
2
-
3
-/**
4
- * eSales Media Formilicious for Contao Open Source CMS
5
- *
6
- * Copyright (C) 2013-2014 eSalesMedia
7
- *
8
- * @package    eSM_formilicious
9
- * @link       http://www.esales-media.de
10
- * @license    http://www.gnu.org/licenses/lgpl-3.0.html LGPL
11
- *
12
- * @author     Benjamin Roth <benjamin@esales-media.de>
13
- */
14
-
15
-namespace eSM_formilicious;
16
-
17
-abstract class Widget extends \Contao\Widget
18
-{
19
-
20
-  /**
21
-   * Extract the Widget attributes from a Data Container array
22
-   *
23
-   * @param array  $arrData  The field configuration array
24
-   * @param string $strName  The field name in the form
25
-   * @param mixed  $varValue The field value
26
-   * @param string $strField The field name in the database
27
-   * @param string $strTable The table name in the database
28
-   * @param object $objDca   An optional DataContainer object
29
-   *
30
-   * @return array An attributes array that can be passed to a widget
31
-   */
32
-  public static function getAttributesFromDca($arrData, $strName, $varValue=null, $strField='', $strTable='', $objDca=null)
33
-  {
34
-    $arrAttributes = parent::getAttributesFromDca($arrData, $strName, $varValue, $strField, $strTable, $objDca);
35
-
36
-    if (isset($arrData['eval']['eSM_fl_width']))
37
-    {
38
-      $arrAttributes['eSM_fl_width'] = $arrData['eval']['eSM_fl_width'];
39
-    }
40
-
41
-    if (isset($arrData['eval']['eSM_fl_clear']))
42
-    {
43
-      $arrAttributes['eSM_fl_clear'] = $arrData['eval']['eSM_fl_clear'];
44
-    }
45
-
46
-    if (isset($arrData['eval']['eSM_fl_class']))
47
-    {
48
-      $arrAttributes['eSM_fl_class'] = $arrData['eval']['eSM_fl_class'];
49
-    }
50
-
51
-    if (isset($arrData['eval']['eSM_fl_lblpadding']))
52
-    {
53
-      $arrAttributes['eSM_fl_lblpadding'] = $arrData['eval']['eSM_fl_lblpadding'];
54
-    }
55
-
56
-    if (isset($arrData['eval']['eSM_fl_alignment']))
57
-    {
58
-      $arrAttributes['eSM_fl_alignment'] = $arrData['eval']['eSM_fl_alignment'];
59
-    }
60
-
61
-    if (isset($arrData['eval']['eSM_fl_fieldClass']))
62
-    {
63
-      $arrAttributes['class'] = trim($arrAttributes['class'].' '.$arrData['eval']['eSM_fl_fieldClass']);
64
-    }
65
-
66
-    return $arrAttributes;
67
-  }
68
-}
69 0
\ No newline at end of file
... ...
@@ -25,9 +25,6 @@ ClassLoader::addNamespaces(array
25 25
  */
26 26
 ClassLoader::addClasses(array
27 27
 (
28
-	// Classes
29
-	'eSM_formilicious\Widget' => 'system/modules/eSM_formilicious/classes/Widget.php',
30
-
31 28
   // Hooks
32 29
 	'eSM_formilicious\FormiliciousHooks' => 'system/modules/eSM_formilicious/hooks/FormiliciousHooks.php',
33 30
 
... ...
@@ -16,4 +16,5 @@
16 16
 $GLOBALS['TL_HOOKS']['loadDataContainer'][] = array('\FormiliciousHooks','eSMLoadDataContainer');
17 17
 $GLOBALS['TL_HOOKS']['loadFormField'][] = array('\FormiliciousHooks','eSMLoadFormField');
18 18
 $GLOBALS['FE_MOD']['user']['registration'] = '\eSM_formilicious\ModuleRegistration';
19
-$GLOBALS['FE_MOD']['user']['personalData'] = '\eSM_formilicious\ModulePersonalData';
20 19
\ No newline at end of file
20
+$GLOBALS['FE_MOD']['user']['personalData'] = '\eSM_formilicious\ModulePersonalData';
21
+$GLOBALS['TL_HOOKS']['getAttributesFromDca'][] = array('\FormiliciousHooks','eSMGetAttributesFromDca');
21 22
\ No newline at end of file
... ...
@@ -14,6 +14,9 @@
14 14
 
15 15
 namespace eSM_formilicious;
16 16
 
17
+use Contao\Controller;
18
+use Contao\DataContainer;
19
+
17 20
 class FormiliciousHooks extends \Controller
18 21
 {
19 22
 
... ...
@@ -115,4 +118,50 @@ class FormiliciousHooks extends \Controller
115 118
 
116 119
     return $objWidget;
117 120
   }
121
+
122
+  /**
123
+   * @param array               $arrAttributes
124
+   * @param DataContainer|null  $objDca
125
+   *
126
+   * @return array
127
+   */
128
+  public function eSMGetAttributesFromDca($arrAttributes, $objDca)
129
+  {
130
+    if ($objDca instanceof DataContainer && $objDca->field)
131
+    {
132
+      Controller::loadDataContainer($objDca->table);
133
+      $arrData = $GLOBALS['TL_DCA'][$objDca->table]['fields'][$objDca->field];
134
+
135
+      if (isset($arrData['eval']['eSM_fl_width']))
136
+      {
137
+        $arrAttributes['eSM_fl_width'] = $arrData['eval']['eSM_fl_width'];
138
+      }
139
+
140
+      if (isset($arrData['eval']['eSM_fl_clear']))
141
+      {
142
+        $arrAttributes['eSM_fl_clear'] = $arrData['eval']['eSM_fl_clear'];
143
+      }
144
+
145
+      if (isset($arrData['eval']['eSM_fl_class']))
146
+      {
147
+        $arrAttributes['eSM_fl_class'] = $arrData['eval']['eSM_fl_class'];
148
+      }
149
+
150
+      if (isset($arrData['eval']['eSM_fl_lblpadding']))
151
+      {
152
+        $arrAttributes['eSM_fl_lblpadding'] = $arrData['eval']['eSM_fl_lblpadding'];
153
+      }
154
+
155
+      if (isset($arrData['eval']['eSM_fl_alignment']))
156
+      {
157
+        $arrAttributes['eSM_fl_alignment'] = $arrData['eval']['eSM_fl_alignment'];
158
+      }
159
+
160
+      if (isset($arrData['eval']['eSM_fl_fieldClass']))
161
+      {
162
+        $arrAttributes['class'] = trim($arrAttributes['class'].' '.$arrData['eval']['eSM_fl_fieldClass']);
163
+      }
164
+    }
165
+    return $arrAttributes;
166
+  }
118 167
 }
119 168
\ No newline at end of file