Completed
Branch BUG-11015-form-help-text (fc6303)
by
unknown
83:02 queued 73:16
created
form_sections/strategies/layout/EE_Form_Section_Layout_Base.strategy.php 2 patches
Indentation   +254 added lines, -254 removed lines patch added patch discarded remove patch
@@ -15,258 +15,258 @@
 block discarded – undo
15 15
 abstract class EE_Form_Section_Layout_Base
16 16
 {
17 17
 
18
-    /**
19
-     * Form form section to lay out
20
-     *
21
-     * @var EE_Form_Section_Proper
22
-     */
23
-    protected $_form_section;
24
-
25
-
26
-
27
-    /**
28
-     *  __construct
29
-     */
30
-    public function __construct()
31
-    {
32
-    }
33
-
34
-
35
-
36
-    /**
37
-     * The form section on which this strategy is to perform
38
-     *
39
-     * @param EE_Form_Section_Proper $form
40
-     */
41
-    public function _construct_finalize(EE_Form_Section_Proper $form)
42
-    {
43
-        $this->_form_section = $form;
44
-    }
45
-
46
-
47
-
48
-    /**
49
-     * @return EE_Form_Section_Proper
50
-     */
51
-    public function form_section()
52
-    {
53
-        return $this->_form_section;
54
-    }
55
-
56
-
57
-
58
-    /**
59
-     * Also has teh side effect of enqueuing any needed JS and CSS for
60
-     * this form.
61
-     * Creates all the HTML necessary for displaying this form, its inputs, and
62
-     * proper subsections.
63
-     * Returns the HTML
64
-     *
65
-     * @return string HTML for displaying
66
-     * @throws EE_Error
67
-     */
68
-    public function layout_form()
69
-    {
70
-        $html = '';
71
-        // layout_form_begin
72
-        $html .= apply_filters(
73
-            'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(),
74
-            $this->layout_form_begin(),
75
-            $this->_form_section
76
-        );
77
-        // layout_form_loop
78
-        $html .= apply_filters(
79
-            'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(),
80
-            $this->layout_form_loop(),
81
-            $this->_form_section
82
-        );
83
-        // layout_form_end
84
-        $html .= apply_filters(
85
-            'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(),
86
-            $this->layout_form_end(),
87
-            $this->_form_section
88
-        );
89
-        $html = $this->add_form_section_hooks_and_filters($html);
90
-        return $html;
91
-    }
92
-
93
-
94
-
95
-    /**
96
-     * @return string
97
-     * @throws EE_Error
98
-     */
99
-    public function layout_form_loop()
100
-    {
101
-        $html = '';
102
-        foreach ($this->_form_section->subsections() as $name => $subsection) {
103
-            if ($subsection instanceof EE_Form_Input_Base) {
104
-                $html .= apply_filters(
105
-                    'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_'
106
-                    . $name . '__in_' . $this->_form_section->name(),
107
-                    $this->layout_input($subsection),
108
-                    $this->_form_section,
109
-                    $subsection
110
-                );
111
-            } elseif ($subsection instanceof EE_Form_Section_Base) {
112
-                $html .= apply_filters(
113
-                    'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_'
114
-                    . $name . '__in_' . $this->_form_section->name(),
115
-                    $this->layout_subsection($subsection),
116
-                    $this->_form_section,
117
-                    $subsection
118
-                );
119
-            }
120
-        }
121
-        return $html;
122
-    }
123
-
124
-
125
-
126
-    /**
127
-     * Should be used to start teh form section (Eg a table tag, or a div tag, etc.)
128
-     *
129
-     * @return string
130
-     */
131
-    abstract public function layout_form_begin();
132
-
133
-
134
-
135
-    /**
136
-     * Should be used to end the form section (eg a /table tag, or a /div tag, etc)
137
-     *
138
-     * @return string
139
-     */
140
-    abstract public function layout_form_end();
141
-
142
-
143
-
144
-    /**
145
-     * Should be used internally by layout_form() to layout each input (eg, if this layout
146
-     * is putting each input in a row of its own, this should probably be called by a
147
-     *  foreach loop in layout_form() (WITHOUT adding any content directly within layout_form()'s foreach loop.
148
-     * Eg, this method should add the tr and td tags). This method is exposed in case you want to completely
149
-     * customize the form's layout, but would like to make use of it for laying out
150
-     * 'easy-to-layout' inputs
151
-     *
152
-     * @param EE_Form_Input_Base $input
153
-     * @return string html
154
-     */
155
-    abstract public function layout_input($input);
156
-
157
-
158
-
159
-    /**
160
-     * Similar to layout_input(), should be used internally by layout_form() within a
161
-     * loop to layout each proper subsection. Unlike layout_input(), however, it is assumed
162
-     * that the proper subsection will layout its container, label, etc on its own.
163
-     *
164
-     * @param EE_Form_Section_Base $subsection
165
-     * @return string html
166
-     */
167
-    abstract public function layout_subsection($subsection);
168
-
169
-
170
-
171
-    /**
172
-     * Gets the HTML for the label tag and its contents for the input
173
-     *
174
-     * @param EE_Form_Input_Base $input
175
-     * @return string
176
-     */
177
-    public function display_label($input)
178
-    {
179
-        $class = $input->required()
180
-            ? 'ee-required-label ' . $input->html_label_class()
181
-            : $input->html_label_class();
182
-        $label_text = $input->required()
183
-            ? $input->html_label_text() . '<span class="ee-asterisk">*</span>'
184
-            : $input->html_label_text();
185
-        return '<label id="'
186
-               . $input->html_label_id()
187
-               . '" class="'
188
-               . $class
189
-               . '" style="'
190
-               . $input->html_label_style()
191
-               . '" for="' . $input->html_name()
192
-               . '">'
193
-               . $label_text
194
-               . '</label>';
195
-    }
196
-
197
-
198
-
199
-    /**
200
-     * returns the HTML for the server-side validation errors for the specified input
201
-     * Note that if JS is enabled, it should remove these and instead
202
-     * populate the form's errors in the jquery validate fashion
203
-     * using the localized data provided to the JS
204
-     *
205
-     * @param EE_Form_Input_Base $input
206
-     * @return string
207
-     */
208
-    public function display_errors($input)
209
-    {
210
-        if ($input->get_validation_errors()) {
211
-            return "<label  id='"
212
-                   . $input->html_id()
213
-                   . "-error' class='error' for='{$input->html_name()}'>"
214
-                   . $input->get_validation_error_string()
215
-                   . '</label>';
216
-        }
217
-        return '';
218
-    }
219
-
220
-
221
-
222
-    /**
223
-     * Displays the help span for the specified input
224
-     *
225
-     * @param EE_Form_Input_Base $input
226
-     * @return string
227
-     */
228
-    public function display_help_text($input)
229
-    {
230
-        $help_text  = $input->html_help_text();
231
-        if ($help_text !== '' && $help_text !== null) {
232
-            $tag = is_admin() ? 'p' : 'span';
233
-            return '<'
234
-                   . $tag
235
-                   . ' id="'
236
-                   . $input->html_id()
237
-                   . '-help" class="'
238
-                   . $input->html_help_class()
239
-                   . '" style="'
240
-                   . $input->html_help_style()
241
-                   . '">'
242
-                   . $help_text
243
-                   . '</'
244
-                   . $tag
245
-                   . '>';
246
-        }
247
-        return '';
248
-    }
249
-
250
-
251
-
252
-    /**
253
-     * Does an action and hook onto the end of teh form
254
-     *
255
-     * @param string $html
256
-     * @return string
257
-     */
258
-    public function add_form_section_hooks_and_filters($html)
259
-    {
260
-        // replace dashes and spaces with underscores
261
-        $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id());
262
-        do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section);
263
-        $html = (string) apply_filters(
264
-            'AFEE__Form_Section_Layout__' . $hook_name . '__html',
265
-            $html,
266
-            $this->_form_section
267
-        );
268
-        $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->';
269
-        $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->';
270
-        return $html;
271
-    }
18
+	/**
19
+	 * Form form section to lay out
20
+	 *
21
+	 * @var EE_Form_Section_Proper
22
+	 */
23
+	protected $_form_section;
24
+
25
+
26
+
27
+	/**
28
+	 *  __construct
29
+	 */
30
+	public function __construct()
31
+	{
32
+	}
33
+
34
+
35
+
36
+	/**
37
+	 * The form section on which this strategy is to perform
38
+	 *
39
+	 * @param EE_Form_Section_Proper $form
40
+	 */
41
+	public function _construct_finalize(EE_Form_Section_Proper $form)
42
+	{
43
+		$this->_form_section = $form;
44
+	}
45
+
46
+
47
+
48
+	/**
49
+	 * @return EE_Form_Section_Proper
50
+	 */
51
+	public function form_section()
52
+	{
53
+		return $this->_form_section;
54
+	}
55
+
56
+
57
+
58
+	/**
59
+	 * Also has teh side effect of enqueuing any needed JS and CSS for
60
+	 * this form.
61
+	 * Creates all the HTML necessary for displaying this form, its inputs, and
62
+	 * proper subsections.
63
+	 * Returns the HTML
64
+	 *
65
+	 * @return string HTML for displaying
66
+	 * @throws EE_Error
67
+	 */
68
+	public function layout_form()
69
+	{
70
+		$html = '';
71
+		// layout_form_begin
72
+		$html .= apply_filters(
73
+			'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(),
74
+			$this->layout_form_begin(),
75
+			$this->_form_section
76
+		);
77
+		// layout_form_loop
78
+		$html .= apply_filters(
79
+			'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(),
80
+			$this->layout_form_loop(),
81
+			$this->_form_section
82
+		);
83
+		// layout_form_end
84
+		$html .= apply_filters(
85
+			'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(),
86
+			$this->layout_form_end(),
87
+			$this->_form_section
88
+		);
89
+		$html = $this->add_form_section_hooks_and_filters($html);
90
+		return $html;
91
+	}
92
+
93
+
94
+
95
+	/**
96
+	 * @return string
97
+	 * @throws EE_Error
98
+	 */
99
+	public function layout_form_loop()
100
+	{
101
+		$html = '';
102
+		foreach ($this->_form_section->subsections() as $name => $subsection) {
103
+			if ($subsection instanceof EE_Form_Input_Base) {
104
+				$html .= apply_filters(
105
+					'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_'
106
+					. $name . '__in_' . $this->_form_section->name(),
107
+					$this->layout_input($subsection),
108
+					$this->_form_section,
109
+					$subsection
110
+				);
111
+			} elseif ($subsection instanceof EE_Form_Section_Base) {
112
+				$html .= apply_filters(
113
+					'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_'
114
+					. $name . '__in_' . $this->_form_section->name(),
115
+					$this->layout_subsection($subsection),
116
+					$this->_form_section,
117
+					$subsection
118
+				);
119
+			}
120
+		}
121
+		return $html;
122
+	}
123
+
124
+
125
+
126
+	/**
127
+	 * Should be used to start teh form section (Eg a table tag, or a div tag, etc.)
128
+	 *
129
+	 * @return string
130
+	 */
131
+	abstract public function layout_form_begin();
132
+
133
+
134
+
135
+	/**
136
+	 * Should be used to end the form section (eg a /table tag, or a /div tag, etc)
137
+	 *
138
+	 * @return string
139
+	 */
140
+	abstract public function layout_form_end();
141
+
142
+
143
+
144
+	/**
145
+	 * Should be used internally by layout_form() to layout each input (eg, if this layout
146
+	 * is putting each input in a row of its own, this should probably be called by a
147
+	 *  foreach loop in layout_form() (WITHOUT adding any content directly within layout_form()'s foreach loop.
148
+	 * Eg, this method should add the tr and td tags). This method is exposed in case you want to completely
149
+	 * customize the form's layout, but would like to make use of it for laying out
150
+	 * 'easy-to-layout' inputs
151
+	 *
152
+	 * @param EE_Form_Input_Base $input
153
+	 * @return string html
154
+	 */
155
+	abstract public function layout_input($input);
156
+
157
+
158
+
159
+	/**
160
+	 * Similar to layout_input(), should be used internally by layout_form() within a
161
+	 * loop to layout each proper subsection. Unlike layout_input(), however, it is assumed
162
+	 * that the proper subsection will layout its container, label, etc on its own.
163
+	 *
164
+	 * @param EE_Form_Section_Base $subsection
165
+	 * @return string html
166
+	 */
167
+	abstract public function layout_subsection($subsection);
168
+
169
+
170
+
171
+	/**
172
+	 * Gets the HTML for the label tag and its contents for the input
173
+	 *
174
+	 * @param EE_Form_Input_Base $input
175
+	 * @return string
176
+	 */
177
+	public function display_label($input)
178
+	{
179
+		$class = $input->required()
180
+			? 'ee-required-label ' . $input->html_label_class()
181
+			: $input->html_label_class();
182
+		$label_text = $input->required()
183
+			? $input->html_label_text() . '<span class="ee-asterisk">*</span>'
184
+			: $input->html_label_text();
185
+		return '<label id="'
186
+			   . $input->html_label_id()
187
+			   . '" class="'
188
+			   . $class
189
+			   . '" style="'
190
+			   . $input->html_label_style()
191
+			   . '" for="' . $input->html_name()
192
+			   . '">'
193
+			   . $label_text
194
+			   . '</label>';
195
+	}
196
+
197
+
198
+
199
+	/**
200
+	 * returns the HTML for the server-side validation errors for the specified input
201
+	 * Note that if JS is enabled, it should remove these and instead
202
+	 * populate the form's errors in the jquery validate fashion
203
+	 * using the localized data provided to the JS
204
+	 *
205
+	 * @param EE_Form_Input_Base $input
206
+	 * @return string
207
+	 */
208
+	public function display_errors($input)
209
+	{
210
+		if ($input->get_validation_errors()) {
211
+			return "<label  id='"
212
+				   . $input->html_id()
213
+				   . "-error' class='error' for='{$input->html_name()}'>"
214
+				   . $input->get_validation_error_string()
215
+				   . '</label>';
216
+		}
217
+		return '';
218
+	}
219
+
220
+
221
+
222
+	/**
223
+	 * Displays the help span for the specified input
224
+	 *
225
+	 * @param EE_Form_Input_Base $input
226
+	 * @return string
227
+	 */
228
+	public function display_help_text($input)
229
+	{
230
+		$help_text  = $input->html_help_text();
231
+		if ($help_text !== '' && $help_text !== null) {
232
+			$tag = is_admin() ? 'p' : 'span';
233
+			return '<'
234
+				   . $tag
235
+				   . ' id="'
236
+				   . $input->html_id()
237
+				   . '-help" class="'
238
+				   . $input->html_help_class()
239
+				   . '" style="'
240
+				   . $input->html_help_style()
241
+				   . '">'
242
+				   . $help_text
243
+				   . '</'
244
+				   . $tag
245
+				   . '>';
246
+		}
247
+		return '';
248
+	}
249
+
250
+
251
+
252
+	/**
253
+	 * Does an action and hook onto the end of teh form
254
+	 *
255
+	 * @param string $html
256
+	 * @return string
257
+	 */
258
+	public function add_form_section_hooks_and_filters($html)
259
+	{
260
+		// replace dashes and spaces with underscores
261
+		$hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id());
262
+		do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section);
263
+		$html = (string) apply_filters(
264
+			'AFEE__Form_Section_Layout__' . $hook_name . '__html',
265
+			$html,
266
+			$this->_form_section
267
+		);
268
+		$html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->';
269
+		$html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->';
270
+		return $html;
271
+	}
272 272
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -70,19 +70,19 @@  discard block
 block discarded – undo
70 70
         $html = '';
71 71
         // layout_form_begin
72 72
         $html .= apply_filters(
73
-            'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(),
73
+            'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_'.$this->_form_section->name(),
74 74
             $this->layout_form_begin(),
75 75
             $this->_form_section
76 76
         );
77 77
         // layout_form_loop
78 78
         $html .= apply_filters(
79
-            'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(),
79
+            'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_'.$this->_form_section->name(),
80 80
             $this->layout_form_loop(),
81 81
             $this->_form_section
82 82
         );
83 83
         // layout_form_end
84 84
         $html .= apply_filters(
85
-            'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(),
85
+            'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_'.$this->_form_section->name(),
86 86
             $this->layout_form_end(),
87 87
             $this->_form_section
88 88
         );
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
             if ($subsection instanceof EE_Form_Input_Base) {
104 104
                 $html .= apply_filters(
105 105
                     'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_'
106
-                    . $name . '__in_' . $this->_form_section->name(),
106
+                    . $name.'__in_'.$this->_form_section->name(),
107 107
                     $this->layout_input($subsection),
108 108
                     $this->_form_section,
109 109
                     $subsection
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
             } elseif ($subsection instanceof EE_Form_Section_Base) {
112 112
                 $html .= apply_filters(
113 113
                     'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_'
114
-                    . $name . '__in_' . $this->_form_section->name(),
114
+                    . $name.'__in_'.$this->_form_section->name(),
115 115
                     $this->layout_subsection($subsection),
116 116
                     $this->_form_section,
117 117
                     $subsection
@@ -177,10 +177,10 @@  discard block
 block discarded – undo
177 177
     public function display_label($input)
178 178
     {
179 179
         $class = $input->required()
180
-            ? 'ee-required-label ' . $input->html_label_class()
180
+            ? 'ee-required-label '.$input->html_label_class()
181 181
             : $input->html_label_class();
182 182
         $label_text = $input->required()
183
-            ? $input->html_label_text() . '<span class="ee-asterisk">*</span>'
183
+            ? $input->html_label_text().'<span class="ee-asterisk">*</span>'
184 184
             : $input->html_label_text();
185 185
         return '<label id="'
186 186
                . $input->html_label_id()
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
                . $class
189 189
                . '" style="'
190 190
                . $input->html_label_style()
191
-               . '" for="' . $input->html_name()
191
+               . '" for="'.$input->html_name()
192 192
                . '">'
193 193
                . $label_text
194 194
                . '</label>';
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
      */
228 228
     public function display_help_text($input)
229 229
     {
230
-        $help_text  = $input->html_help_text();
230
+        $help_text = $input->html_help_text();
231 231
         if ($help_text !== '' && $help_text !== null) {
232 232
             $tag = is_admin() ? 'p' : 'span';
233 233
             return '<'
@@ -259,14 +259,14 @@  discard block
 block discarded – undo
259 259
     {
260 260
         // replace dashes and spaces with underscores
261 261
         $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id());
262
-        do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section);
262
+        do_action('AHEE__Form_Section_Layout__'.$hook_name, $this->_form_section);
263 263
         $html = (string) apply_filters(
264
-            'AFEE__Form_Section_Layout__' . $hook_name . '__html',
264
+            'AFEE__Form_Section_Layout__'.$hook_name.'__html',
265 265
             $html,
266 266
             $this->_form_section
267 267
         );
268
-        $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->';
269
-        $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->';
268
+        $html .= EEH_HTML::nl().'<!-- AHEE__Form_Section_Layout__'.$hook_name.'__html -->';
269
+        $html .= EEH_HTML::nl().'<!-- AFEE__Form_Section_Layout__'.$hook_name.' -->';
270 270
         return $html;
271 271
     }
272 272
 }
Please login to merge, or discard this patch.