Browse code

Use getAttributesFromDca hook instead of overwriting Contao core class

Benjamin Roth authored on07/10/2019 12:10:12
Showing1 changed files
... ...
@@ -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
Browse code

Add default value to select single value select fields

Benjamin Roth authored on14/06/2017 21:19:53
Showing1 changed files
... ...
@@ -73,4 +73,46 @@ class FormiliciousHooks extends \Controller
73 73
 			}
74 74
 		}
75 75
 	}
76
+
77
+  /**
78
+   * Hook for adding default value functionality to single value select fields
79
+   * @param \Widget $objWidget
80
+   * @param $strForm
81
+   * @param $arrForm
82
+   * @return \Widget
83
+   */
84
+  public function eSMLoadFormField(\Widget $objWidget, $strForm, $arrForm)
85
+  {
86
+    // Only apply to select fields with multiple off
87
+    if ($objWidget->type == 'select' && !$objWidget->multiple && $objWidget->value != '')
88
+    {
89
+      $arrOptions = (array) $objWidget->options;
90
+      $intSelOption = null;
91
+
92
+      // Iterate options and search for selected values
93
+      foreach ($arrOptions as $k => $option)
94
+      {
95
+        if (!$option['group'] && $option['value'] == $objWidget->value)
96
+        {
97
+          $intSelOption = $k;
98
+          break;
99
+        } else if (!$option['group'] && $option['default'])
100
+        {
101
+          $intSelOption = $k;
102
+        }
103
+        unset($arrOptions[$k]['default']);
104
+      }
105
+
106
+      // Set proper default option
107
+      if ($intSelOption !== null)
108
+      {
109
+        $arrOptions[$intSelOption]['default'] = '1';
110
+      }
111
+
112
+      // Override widget with new options array
113
+      $objWidget->options = $arrOptions;
114
+    }
115
+
116
+    return $objWidget;
117
+  }
76 118
 }
77 119
\ No newline at end of file
Browse code

The headline element doesn't need any formilicious config settings

Benjamin Roth authored on17/08/2015 17:14:47
Showing1 changed files
... ...
@@ -21,7 +21,7 @@ class FormiliciousHooks extends \Controller
21 21
 	 * Array containing all fields which shouldn't use Formilicous extensions
22 22
 	 * @var array
23 23
 	 */
24
-	protected $arrNoFl = array('__selector__','fieldsetfsStart','fieldsetfsStop','hidden','html');
24
+	protected $arrNoFl = array('__selector__','fieldsetfsStart','fieldsetfsStop','hidden','html','headline');
25 25
 
26 26
 	/**
27 27
 	 * Array containing all fields which shouldn't use Formilicous custom class
Browse code

Don't use formilicious custom class on non form elements

Benjamin Roth authored on17/08/2015 17:09:24
Showing1 changed files
... ...
@@ -24,6 +24,12 @@ class FormiliciousHooks extends \Controller
24 24
 	protected $arrNoFl = array('__selector__','fieldsetfsStart','fieldsetfsStop','hidden','html');
25 25
 
26 26
 	/**
27
+	 * Array containing all fields which shouldn't use Formilicous custom class
28
+	 * @var array
29
+	 */
30
+	protected $arrNoCustClass = array('explanation');
31
+
32
+	/**
27 33
 	 * Hook for adding Formilicious fields to the form editor
28 34
 	 * @param $strName
29 35
 	 */
... ...
@@ -41,7 +47,11 @@ class FormiliciousHooks extends \Controller
41 47
 			{
42 48
 				if (!in_array($k,$this->arrNoFl))
43 49
 				{
44
-					$strFl = ';{formilicious_legend},eSM_fl_width,eSM_fl_clear,eSM_fl_class';
50
+					$strFl = ';{formilicious_legend},eSM_fl_width,eSM_fl_clear';
51
+					if (!in_array($k,$this->arrNoCustClass))
52
+					{
53
+						$strFl.= ',eSM_fl_class';
54
+					}
45 55
 					if ($k == 'submit')
46 56
 					{
47 57
 						$strFl.= ',eSM_fl_lblpadding,eSM_fl_alignment';
Browse code

Exclude html element from formilicious

Benjamin Roth authored on17/08/2015 17:06:28
Showing1 changed files
... ...
@@ -21,7 +21,7 @@ class FormiliciousHooks extends \Controller
21 21
 	 * Array containing all fields which shouldn't use Formilicous extensions
22 22
 	 * @var array
23 23
 	 */
24
-	protected $arrNoFl = array('__selector__','fieldsetfsStart','fieldsetfsStop','hidden');
24
+	protected $arrNoFl = array('__selector__','fieldsetfsStart','fieldsetfsStop','hidden','html');
25 25
 
26 26
 	/**
27 27
 	 * Hook for adding Formilicious fields to the form editor
Browse code

Initial commit

Benjamin Roth authored on27/03/2015 10:45:40
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,66 @@
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
+class FormiliciousHooks extends \Controller
18
+{
19
+
20
+	/**
21
+	 * Array containing all fields which shouldn't use Formilicous extensions
22
+	 * @var array
23
+	 */
24
+	protected $arrNoFl = array('__selector__','fieldsetfsStart','fieldsetfsStop','hidden');
25
+
26
+	/**
27
+	 * Hook for adding Formilicious fields to the form editor
28
+	 * @param $strName
29
+	 */
30
+	public function eSMLoadDataContainer($strName)
31
+	{
32
+		if ($strName != 'tl_form_field')
33
+		{
34
+			return;
35
+		}
36
+
37
+		// Hook in the Formilicious fields
38
+		if (is_array($GLOBALS['TL_DCA']['tl_form_field']['palettes']))
39
+		{
40
+			foreach (array_keys($GLOBALS['TL_DCA']['tl_form_field']['palettes']) as $k)
41
+			{
42
+				if (!in_array($k,$this->arrNoFl))
43
+				{
44
+					$strFl = ';{formilicious_legend},eSM_fl_width,eSM_fl_clear,eSM_fl_class';
45
+					if ($k == 'submit')
46
+					{
47
+						$strFl.= ',eSM_fl_lblpadding,eSM_fl_alignment';
48
+					}
49
+					$intPos = strpos($GLOBALS['TL_DCA']['tl_form_field']['palettes'][$k], ';{expert_legend');
50
+					$intDupe = strpos($GLOBALS['TL_DCA']['tl_form_field']['palettes'][$k], ';{formilicious_legend');
51
+					if ($intPos !== false && $intDupe === false)
52
+					{
53
+						$GLOBALS['TL_DCA']['tl_form_field']['palettes'][$k] =
54
+							substr($GLOBALS['TL_DCA']['tl_form_field']['palettes'][$k], 0, $intPos) .
55
+							$strFl .
56
+							substr($GLOBALS['TL_DCA']['tl_form_field']['palettes'][$k], $intPos);
57
+					}
58
+					else if ($intDupe === false)
59
+					{
60
+						$GLOBALS['TL_DCA']['tl_form_field']['palettes'][$k] .= $strFl;
61
+					}
62
+				}
63
+			}
64
+		}
65
+	}
66
+}
0 67
\ No newline at end of file