Completed
Branch BUG/3575-event-deletion-previe... (bbeda1)
by
unknown
06:40 queued 04:49
created
core/libraries/form_sections/form_handlers/InvalidFormHandlerException.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -13,25 +13,25 @@
 block discarded – undo
13 13
 class InvalidFormHandlerException extends \UnexpectedValueException
14 14
 {
15 15
 
16
-    /**
17
-     * InvalidFormHandlerException constructor.
18
-     *
19
-     * @param string     $actual the FormHandler object that was received
20
-     * @param string     $message
21
-     * @param int        $code
22
-     * @param \Exception $previous
23
-     */
24
-    public function __construct($actual, $message = '', $code = 0, \Exception $previous = null)
25
-    {
26
-        if (empty($message)) {
27
-            $message = sprintf(
28
-                esc_html__(
29
-                    'A valid Form Handler was expected but instead "%1$s" was received.',
30
-                    'event_espresso'
31
-                ),
32
-                $actual
33
-            );
34
-        }
35
-        parent::__construct($message, $code, $previous);
36
-    }
16
+	/**
17
+	 * InvalidFormHandlerException constructor.
18
+	 *
19
+	 * @param string     $actual the FormHandler object that was received
20
+	 * @param string     $message
21
+	 * @param int        $code
22
+	 * @param \Exception $previous
23
+	 */
24
+	public function __construct($actual, $message = '', $code = 0, \Exception $previous = null)
25
+	{
26
+		if (empty($message)) {
27
+			$message = sprintf(
28
+				esc_html__(
29
+					'A valid Form Handler was expected but instead "%1$s" was received.',
30
+					'event_espresso'
31
+				),
32
+				$actual
33
+			);
34
+		}
35
+		parent::__construct($message, $code, $previous);
36
+	}
37 37
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/base/EE_Form_Section_Base.form.php 2 patches
Indentation   +476 added lines, -476 removed lines patch added patch discarded remove patch
@@ -15,486 +15,486 @@
 block discarded – undo
15 15
 abstract class EE_Form_Section_Base
16 16
 {
17 17
 
18
-    /**
19
-     * the URL the form is submitted to
20
-     *
21
-     * @var string
22
-     */
23
-    protected $_action;
24
-
25
-    /**
26
-     * POST (default) or GET
27
-     *
28
-     * @var string
29
-     */
30
-    protected $_method;
31
-
32
-    /**
33
-     * html_id and html_name are derived from this by default
34
-     *
35
-     * @var string
36
-     */
37
-    protected $_name;
38
-
39
-    /**
40
-     * $_html_id
41
-     * @var string
42
-     */
43
-    protected $_html_id;
44
-
45
-    /**
46
-     * $_html_class
47
-     * @var string
48
-     */
49
-    protected $_html_class;
50
-
51
-    /**
52
-     * $_html_style
53
-     * @var string
54
-     */
55
-    protected $_html_style;
56
-
57
-    /**
58
-     * $_other_html_attributes
59
-     * @var string
60
-     */
61
-    protected $_other_html_attributes;
62
-
63
-    /**
64
-     * The form section of which this form section is a part
65
-     *
66
-     * @var EE_Form_Section_Proper
67
-     */
68
-    protected $_parent_section;
69
-
70
-    /**
71
-     * flag indicating that _construct_finalize has been called.
72
-     * If it has not been called and we try to use functions which require it, we call it
73
-     * with no parameters. But normally, _construct_finalize should be called by the instantiating class
74
-     *
75
-     * @var boolean
76
-     */
77
-    protected $_construction_finalized;
78
-
79
-    /**
80
-     * Strategy for parsing the form HTML upon display
81
-     *
82
-     * @var FormHtmlFilter
83
-     */
84
-    protected $_form_html_filter;
85
-
86
-
87
-    /**
88
-     * @param array $options_array {
89
-     * @type        $name          string the name for this form section, if you want to explicitly define it
90
-     *                             }
91
-     * @throws InvalidDataTypeException
92
-     */
93
-    public function __construct($options_array = array())
94
-    {
95
-        // used by display strategies
96
-        // assign incoming values to properties
97
-        foreach ($options_array as $key => $value) {
98
-            $key = '_' . $key;
99
-            if (property_exists($this, $key) && empty($this->{$key})) {
100
-                $this->{$key} = $value;
101
-                if ($key === '_subsections' && ! is_array($value)) {
102
-                    throw new InvalidDataTypeException($key, $value, 'array');
103
-                }
104
-            }
105
-        }
106
-        // set parser which allows the form section's rendered HTML to be filtered
107
-        if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) {
108
-            $this->_form_html_filter = $options_array['form_html_filter'];
109
-        }
110
-    }
111
-
112
-
113
-
114
-    /**
115
-     * @param $parent_form_section
116
-     * @param $name
117
-     * @throws \EE_Error
118
-     */
119
-    protected function _construct_finalize($parent_form_section, $name)
120
-    {
121
-        $this->_construction_finalized = true;
122
-        $this->_parent_section = $parent_form_section;
123
-        if ($name !== null) {
124
-            $this->_name = $name;
125
-        }
126
-    }
127
-
128
-
129
-
130
-    /**
131
-     * make sure construction finalized was called, otherwise children might not be ready
132
-     *
133
-     * @return void
134
-     * @throws \EE_Error
135
-     */
136
-    public function ensure_construct_finalized_called()
137
-    {
138
-        if (! $this->_construction_finalized) {
139
-            $this->_construct_finalize($this->_parent_section, $this->_name);
140
-        }
141
-    }
142
-
143
-
144
-
145
-    /**
146
-     * @return string
147
-     */
148
-    public function action()
149
-    {
150
-        return $this->_action;
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * @param string $action
157
-     */
158
-    public function set_action($action)
159
-    {
160
-        $this->_action = $action;
161
-    }
162
-
163
-
164
-
165
-    /**
166
-     * @return string
167
-     */
168
-    public function method()
169
-    {
170
-        return ! empty($this->_method) ? $this->_method : 'POST';
171
-    }
172
-
173
-
174
-
175
-    /**
176
-     * @param string $method
177
-     */
178
-    public function set_method($method)
179
-    {
180
-        switch ($method) {
181
-            case 'get':
182
-            case 'GET':
183
-                $this->_method = 'GET';
184
-                break;
185
-            default:
186
-                $this->_method = 'POST';
187
-        }
188
-    }
189
-
190
-
191
-
192
-    /**
193
-     * Sets the html_id to its default value, if none was specified in the constructor.
194
-     * Calculation involves using the name and the parent's html id
195
-     * return void
196
-     *
197
-     * @throws \EE_Error
198
-     */
199
-    protected function _set_default_html_id_if_empty()
200
-    {
201
-        if (! $this->_html_id) {
202
-            if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
203
-                $this->_html_id = $this->_parent_section->html_id()
204
-                                  . '-'
205
-                                  . $this->_prep_name_for_html_id($this->name());
206
-            } else {
207
-                $this->_html_id = $this->_prep_name_for_html_id($this->name());
208
-            }
209
-        }
210
-    }
211
-
212
-
213
-
214
-    /**
215
-     * _prep_name_for_html_id
216
-     *
217
-     * @param $name
218
-     * @return string
219
-     */
220
-    private function _prep_name_for_html_id($name)
221
-    {
222
-        return sanitize_key(str_replace(array(' ', ' ', '_'), '-', $name));
223
-    }
18
+	/**
19
+	 * the URL the form is submitted to
20
+	 *
21
+	 * @var string
22
+	 */
23
+	protected $_action;
24
+
25
+	/**
26
+	 * POST (default) or GET
27
+	 *
28
+	 * @var string
29
+	 */
30
+	protected $_method;
31
+
32
+	/**
33
+	 * html_id and html_name are derived from this by default
34
+	 *
35
+	 * @var string
36
+	 */
37
+	protected $_name;
38
+
39
+	/**
40
+	 * $_html_id
41
+	 * @var string
42
+	 */
43
+	protected $_html_id;
44
+
45
+	/**
46
+	 * $_html_class
47
+	 * @var string
48
+	 */
49
+	protected $_html_class;
50
+
51
+	/**
52
+	 * $_html_style
53
+	 * @var string
54
+	 */
55
+	protected $_html_style;
56
+
57
+	/**
58
+	 * $_other_html_attributes
59
+	 * @var string
60
+	 */
61
+	protected $_other_html_attributes;
62
+
63
+	/**
64
+	 * The form section of which this form section is a part
65
+	 *
66
+	 * @var EE_Form_Section_Proper
67
+	 */
68
+	protected $_parent_section;
69
+
70
+	/**
71
+	 * flag indicating that _construct_finalize has been called.
72
+	 * If it has not been called and we try to use functions which require it, we call it
73
+	 * with no parameters. But normally, _construct_finalize should be called by the instantiating class
74
+	 *
75
+	 * @var boolean
76
+	 */
77
+	protected $_construction_finalized;
78
+
79
+	/**
80
+	 * Strategy for parsing the form HTML upon display
81
+	 *
82
+	 * @var FormHtmlFilter
83
+	 */
84
+	protected $_form_html_filter;
85
+
86
+
87
+	/**
88
+	 * @param array $options_array {
89
+	 * @type        $name          string the name for this form section, if you want to explicitly define it
90
+	 *                             }
91
+	 * @throws InvalidDataTypeException
92
+	 */
93
+	public function __construct($options_array = array())
94
+	{
95
+		// used by display strategies
96
+		// assign incoming values to properties
97
+		foreach ($options_array as $key => $value) {
98
+			$key = '_' . $key;
99
+			if (property_exists($this, $key) && empty($this->{$key})) {
100
+				$this->{$key} = $value;
101
+				if ($key === '_subsections' && ! is_array($value)) {
102
+					throw new InvalidDataTypeException($key, $value, 'array');
103
+				}
104
+			}
105
+		}
106
+		// set parser which allows the form section's rendered HTML to be filtered
107
+		if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) {
108
+			$this->_form_html_filter = $options_array['form_html_filter'];
109
+		}
110
+	}
111
+
112
+
113
+
114
+	/**
115
+	 * @param $parent_form_section
116
+	 * @param $name
117
+	 * @throws \EE_Error
118
+	 */
119
+	protected function _construct_finalize($parent_form_section, $name)
120
+	{
121
+		$this->_construction_finalized = true;
122
+		$this->_parent_section = $parent_form_section;
123
+		if ($name !== null) {
124
+			$this->_name = $name;
125
+		}
126
+	}
127
+
128
+
129
+
130
+	/**
131
+	 * make sure construction finalized was called, otherwise children might not be ready
132
+	 *
133
+	 * @return void
134
+	 * @throws \EE_Error
135
+	 */
136
+	public function ensure_construct_finalized_called()
137
+	{
138
+		if (! $this->_construction_finalized) {
139
+			$this->_construct_finalize($this->_parent_section, $this->_name);
140
+		}
141
+	}
142
+
143
+
144
+
145
+	/**
146
+	 * @return string
147
+	 */
148
+	public function action()
149
+	{
150
+		return $this->_action;
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * @param string $action
157
+	 */
158
+	public function set_action($action)
159
+	{
160
+		$this->_action = $action;
161
+	}
162
+
163
+
164
+
165
+	/**
166
+	 * @return string
167
+	 */
168
+	public function method()
169
+	{
170
+		return ! empty($this->_method) ? $this->_method : 'POST';
171
+	}
172
+
173
+
174
+
175
+	/**
176
+	 * @param string $method
177
+	 */
178
+	public function set_method($method)
179
+	{
180
+		switch ($method) {
181
+			case 'get':
182
+			case 'GET':
183
+				$this->_method = 'GET';
184
+				break;
185
+			default:
186
+				$this->_method = 'POST';
187
+		}
188
+	}
189
+
190
+
191
+
192
+	/**
193
+	 * Sets the html_id to its default value, if none was specified in the constructor.
194
+	 * Calculation involves using the name and the parent's html id
195
+	 * return void
196
+	 *
197
+	 * @throws \EE_Error
198
+	 */
199
+	protected function _set_default_html_id_if_empty()
200
+	{
201
+		if (! $this->_html_id) {
202
+			if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
203
+				$this->_html_id = $this->_parent_section->html_id()
204
+								  . '-'
205
+								  . $this->_prep_name_for_html_id($this->name());
206
+			} else {
207
+				$this->_html_id = $this->_prep_name_for_html_id($this->name());
208
+			}
209
+		}
210
+	}
211
+
212
+
213
+
214
+	/**
215
+	 * _prep_name_for_html_id
216
+	 *
217
+	 * @param $name
218
+	 * @return string
219
+	 */
220
+	private function _prep_name_for_html_id($name)
221
+	{
222
+		return sanitize_key(str_replace(array(' ', ' ', '_'), '-', $name));
223
+	}
224 224
 
225 225
 
226 226
 
227
-    /**
228
-     * Returns the HTML, JS, and CSS necessary to display this form section on a page.
229
-     * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action,
230
-     * and call get_html when you want to output the html. Calling get_html_and_js after
231
-     * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary
232
-     * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/
233
-     * and so might stop working anytime.
234
-     *
235
-     * @return string
236
-     */
237
-    public function get_html_and_js()
238
-    {
239
-        return $this->get_html();
240
-    }
227
+	/**
228
+	 * Returns the HTML, JS, and CSS necessary to display this form section on a page.
229
+	 * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action,
230
+	 * and call get_html when you want to output the html. Calling get_html_and_js after
231
+	 * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary
232
+	 * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/
233
+	 * and so might stop working anytime.
234
+	 *
235
+	 * @return string
236
+	 */
237
+	public function get_html_and_js()
238
+	{
239
+		return $this->get_html();
240
+	}
241 241
 
242 242
 
243
-
244
-    /**
245
-     * Gets the HTML for displaying this form section
246
-     *
247
-     * @return string
248
-     */
249
-    abstract public function get_html();
250
-
251
-
252
-    /**
253
-     * @param bool $add_pound_sign
254
-     * @return string
255
-     * @throws EE_Error
256
-     */
257
-    public function html_id($add_pound_sign = false)
258
-    {
259
-        $this->_set_default_html_id_if_empty();
260
-        return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id;
261
-    }
262
-
263
-
264
-
265
-    /**
266
-     * @return string
267
-     */
268
-    public function html_class()
269
-    {
270
-        return $this->_html_class;
271
-    }
272
-
273
-
274
-
275
-    /**
276
-     * @return string
277
-     */
278
-    public function html_style()
279
-    {
280
-        return $this->_html_style;
281
-    }
282
-
283
-
284
-
285
-    /**
286
-     * @param mixed $html_class
287
-     */
288
-    public function set_html_class($html_class)
289
-    {
290
-        $this->_html_class = $html_class;
291
-    }
292
-
293
-
294
-
295
-    /**
296
-     * @param mixed $html_id
297
-     */
298
-    public function set_html_id($html_id)
299
-    {
300
-        $this->_html_id = $html_id;
301
-    }
302
-
303
-
304
-
305
-    /**
306
-     * @param mixed $html_style
307
-     */
308
-    public function set_html_style($html_style)
309
-    {
310
-        $this->_html_style = $html_style;
311
-    }
312
-
313
-
314
-
315
-    /**
316
-     * @param string $other_html_attributes
317
-     */
318
-    public function set_other_html_attributes($other_html_attributes)
319
-    {
320
-        $this->_other_html_attributes = $other_html_attributes;
321
-    }
322
-
323
-
324
-
325
-    /**
326
-     * @return string
327
-     */
328
-    public function other_html_attributes()
329
-    {
330
-        return ! empty($this->_other_html_attributes) ? ' ' . $this->_other_html_attributes : '';
331
-    }
332
-
333
-
334
-
335
-    /**
336
-     * Gets the name of the form section. This is not the same as the HTML name.
337
-     *
338
-     * @throws EE_Error
339
-     * @return string
340
-     */
341
-    public function name()
342
-    {
343
-        if (! $this->_construction_finalized) {
344
-            throw new EE_Error(sprintf(esc_html__(
345
-                'You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'',
346
-                'event_espresso'
347
-            ), get_class($this)));
348
-        }
349
-        return $this->_name;
350
-    }
351
-
352
-
353
-
354
-    /**
355
-     * Gets the parent section
356
-     *
357
-     * @return EE_Form_Section_Proper
358
-     */
359
-    public function parent_section()
360
-    {
361
-        return $this->_parent_section;
362
-    }
363
-
364
-
365
-    /**
366
-     * returns HTML for generating the opening form HTML tag (<form>)
367
-     *
368
-     * @param string $action           the URL the form is submitted to
369
-     * @param string $method           POST (default) or GET
370
-     * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML
371
-     * @return string
372
-     * @throws EE_Error
373
-     */
374
-    public function form_open($action = '', $method = '', $other_attributes = '')
375
-    {
376
-        if (! empty($action)) {
377
-            $this->set_action($action);
378
-        }
379
-        if (! empty($method)) {
380
-            $this->set_method($method);
381
-        }
382
-        $html = EEH_HTML::nl(1, 'form') . '<form';
383
-        $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : '';
384
-        $html .= ' action="' . $this->action() . '"';
385
-        $html .= ' method="' . $this->method() . '"';
386
-        $html .= ' name="' . $this->name() . '"';
387
-        $html .= $other_attributes . '>';
388
-        return $html;
389
-    }
390
-
391
-
392
-
393
-    /**
394
-     * ensures that html id for form either ends in "-form" or "-frm"
395
-     * so that id doesn't conflict/collide with other elements
396
-     *
397
-     * @param string $html_id
398
-     * @return string
399
-     */
400
-    protected function get_html_id_for_form($html_id)
401
-    {
402
-        $strlen = strlen($html_id);
403
-        $html_id = strpos($html_id, '-form') === $strlen - 5 || strpos($html_id, '-frm') === $strlen - 4
404
-            ? $html_id
405
-            : $html_id . '-frm';
406
-        return $html_id;
407
-    }
408
-
409
-
410
-    /**
411
-     * returns HTML for generating the closing form HTML tag (</form>)
412
-     *
413
-     * @return string
414
-     * @throws EE_Error
415
-     */
416
-    public function form_close()
417
-    {
418
-        return EEH_HTML::nl(-1, 'form')
419
-               . '</form>'
420
-               . EEH_HTML::nl()
421
-               . '<!-- end of ee-'
422
-               . $this->html_id()
423
-               . '-form -->'
424
-               . EEH_HTML::nl();
425
-    }
426
-
427
-
428
-
429
-    /**
430
-     * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and
431
-     * wp_enqueue_style; the scripts could have optionally been registered earlier)
432
-     * Default does nothing, but child classes can override
433
-     *
434
-     * @return void
435
-     */
436
-    public function enqueue_js()
437
-    {
438
-        // defaults to enqueue NO js or css
439
-    }
440
-
441
-
442
-
443
-    /**
444
-     * Adds any extra data needed by js. Eventually we'll call wp_localize_script
445
-     * with it, and it will be on each form section's 'other_data' property.
446
-     * By default nothing is added, but child classes can extend this method to add something.
447
-     * Eg, if you have an input that will cause a modal dialog to appear,
448
-     * here you could add an entry like 'modal_dialog_inputs' to this array
449
-     * to map between the input's html ID and the modal dialogue's ID, so that
450
-     * your JS code will know where to find the modal dialog when the input is pressed.
451
-     * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id';
452
-     *
453
-     * @param array $form_other_js_data
454
-     * @return array
455
-     */
456
-    public function get_other_js_data($form_other_js_data = array())
457
-    {
458
-        return $form_other_js_data;
459
-    }
460
-
461
-
462
-
463
-    /**
464
-     * This isn't just the name of an input, it's a path pointing to an input. The
465
-     * path is similar to a folder path: slash (/) means to descend into a subsection,
466
-     * dot-dot-slash (../) means to ascend into the parent section.
467
-     * After a series of slashes and dot-dot-slashes, there should be the name of an input,
468
-     * which will be returned.
469
-     * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
470
-     * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
471
-     * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
472
-     * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
473
-     * Etc
474
-     *
475
-     * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
476
-     * @return EE_Form_Section_Base
477
-     */
478
-    public function find_section_from_path($form_section_path)
479
-    {
480
-        if (strpos($form_section_path, '/') === 0) {
481
-            $form_section_path = substr($form_section_path, strlen('/'));
482
-        }
483
-        if (empty($form_section_path)) {
484
-            return $this;
485
-        }
486
-        if (strpos($form_section_path, '../') === 0) {
487
-            $parent = $this->parent_section();
488
-            $form_section_path = substr($form_section_path, strlen('../'));
489
-            if ($parent instanceof EE_Form_Section_Base) {
490
-                return $parent->find_section_from_path($form_section_path);
491
-            }
492
-            if (empty($form_section_path)) {
493
-                return $this;
494
-            }
495
-        }
496
-        // couldn't find it using simple parent following
497
-        return null;
498
-    }
243
+
244
+	/**
245
+	 * Gets the HTML for displaying this form section
246
+	 *
247
+	 * @return string
248
+	 */
249
+	abstract public function get_html();
250
+
251
+
252
+	/**
253
+	 * @param bool $add_pound_sign
254
+	 * @return string
255
+	 * @throws EE_Error
256
+	 */
257
+	public function html_id($add_pound_sign = false)
258
+	{
259
+		$this->_set_default_html_id_if_empty();
260
+		return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id;
261
+	}
262
+
263
+
264
+
265
+	/**
266
+	 * @return string
267
+	 */
268
+	public function html_class()
269
+	{
270
+		return $this->_html_class;
271
+	}
272
+
273
+
274
+
275
+	/**
276
+	 * @return string
277
+	 */
278
+	public function html_style()
279
+	{
280
+		return $this->_html_style;
281
+	}
282
+
283
+
284
+
285
+	/**
286
+	 * @param mixed $html_class
287
+	 */
288
+	public function set_html_class($html_class)
289
+	{
290
+		$this->_html_class = $html_class;
291
+	}
292
+
293
+
294
+
295
+	/**
296
+	 * @param mixed $html_id
297
+	 */
298
+	public function set_html_id($html_id)
299
+	{
300
+		$this->_html_id = $html_id;
301
+	}
302
+
303
+
304
+
305
+	/**
306
+	 * @param mixed $html_style
307
+	 */
308
+	public function set_html_style($html_style)
309
+	{
310
+		$this->_html_style = $html_style;
311
+	}
312
+
313
+
314
+
315
+	/**
316
+	 * @param string $other_html_attributes
317
+	 */
318
+	public function set_other_html_attributes($other_html_attributes)
319
+	{
320
+		$this->_other_html_attributes = $other_html_attributes;
321
+	}
322
+
323
+
324
+
325
+	/**
326
+	 * @return string
327
+	 */
328
+	public function other_html_attributes()
329
+	{
330
+		return ! empty($this->_other_html_attributes) ? ' ' . $this->_other_html_attributes : '';
331
+	}
332
+
333
+
334
+
335
+	/**
336
+	 * Gets the name of the form section. This is not the same as the HTML name.
337
+	 *
338
+	 * @throws EE_Error
339
+	 * @return string
340
+	 */
341
+	public function name()
342
+	{
343
+		if (! $this->_construction_finalized) {
344
+			throw new EE_Error(sprintf(esc_html__(
345
+				'You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'',
346
+				'event_espresso'
347
+			), get_class($this)));
348
+		}
349
+		return $this->_name;
350
+	}
351
+
352
+
353
+
354
+	/**
355
+	 * Gets the parent section
356
+	 *
357
+	 * @return EE_Form_Section_Proper
358
+	 */
359
+	public function parent_section()
360
+	{
361
+		return $this->_parent_section;
362
+	}
363
+
364
+
365
+	/**
366
+	 * returns HTML for generating the opening form HTML tag (<form>)
367
+	 *
368
+	 * @param string $action           the URL the form is submitted to
369
+	 * @param string $method           POST (default) or GET
370
+	 * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML
371
+	 * @return string
372
+	 * @throws EE_Error
373
+	 */
374
+	public function form_open($action = '', $method = '', $other_attributes = '')
375
+	{
376
+		if (! empty($action)) {
377
+			$this->set_action($action);
378
+		}
379
+		if (! empty($method)) {
380
+			$this->set_method($method);
381
+		}
382
+		$html = EEH_HTML::nl(1, 'form') . '<form';
383
+		$html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : '';
384
+		$html .= ' action="' . $this->action() . '"';
385
+		$html .= ' method="' . $this->method() . '"';
386
+		$html .= ' name="' . $this->name() . '"';
387
+		$html .= $other_attributes . '>';
388
+		return $html;
389
+	}
390
+
391
+
392
+
393
+	/**
394
+	 * ensures that html id for form either ends in "-form" or "-frm"
395
+	 * so that id doesn't conflict/collide with other elements
396
+	 *
397
+	 * @param string $html_id
398
+	 * @return string
399
+	 */
400
+	protected function get_html_id_for_form($html_id)
401
+	{
402
+		$strlen = strlen($html_id);
403
+		$html_id = strpos($html_id, '-form') === $strlen - 5 || strpos($html_id, '-frm') === $strlen - 4
404
+			? $html_id
405
+			: $html_id . '-frm';
406
+		return $html_id;
407
+	}
408
+
409
+
410
+	/**
411
+	 * returns HTML for generating the closing form HTML tag (</form>)
412
+	 *
413
+	 * @return string
414
+	 * @throws EE_Error
415
+	 */
416
+	public function form_close()
417
+	{
418
+		return EEH_HTML::nl(-1, 'form')
419
+			   . '</form>'
420
+			   . EEH_HTML::nl()
421
+			   . '<!-- end of ee-'
422
+			   . $this->html_id()
423
+			   . '-form -->'
424
+			   . EEH_HTML::nl();
425
+	}
426
+
427
+
428
+
429
+	/**
430
+	 * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and
431
+	 * wp_enqueue_style; the scripts could have optionally been registered earlier)
432
+	 * Default does nothing, but child classes can override
433
+	 *
434
+	 * @return void
435
+	 */
436
+	public function enqueue_js()
437
+	{
438
+		// defaults to enqueue NO js or css
439
+	}
440
+
441
+
442
+
443
+	/**
444
+	 * Adds any extra data needed by js. Eventually we'll call wp_localize_script
445
+	 * with it, and it will be on each form section's 'other_data' property.
446
+	 * By default nothing is added, but child classes can extend this method to add something.
447
+	 * Eg, if you have an input that will cause a modal dialog to appear,
448
+	 * here you could add an entry like 'modal_dialog_inputs' to this array
449
+	 * to map between the input's html ID and the modal dialogue's ID, so that
450
+	 * your JS code will know where to find the modal dialog when the input is pressed.
451
+	 * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id';
452
+	 *
453
+	 * @param array $form_other_js_data
454
+	 * @return array
455
+	 */
456
+	public function get_other_js_data($form_other_js_data = array())
457
+	{
458
+		return $form_other_js_data;
459
+	}
460
+
461
+
462
+
463
+	/**
464
+	 * This isn't just the name of an input, it's a path pointing to an input. The
465
+	 * path is similar to a folder path: slash (/) means to descend into a subsection,
466
+	 * dot-dot-slash (../) means to ascend into the parent section.
467
+	 * After a series of slashes and dot-dot-slashes, there should be the name of an input,
468
+	 * which will be returned.
469
+	 * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
470
+	 * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
471
+	 * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
472
+	 * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
473
+	 * Etc
474
+	 *
475
+	 * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
476
+	 * @return EE_Form_Section_Base
477
+	 */
478
+	public function find_section_from_path($form_section_path)
479
+	{
480
+		if (strpos($form_section_path, '/') === 0) {
481
+			$form_section_path = substr($form_section_path, strlen('/'));
482
+		}
483
+		if (empty($form_section_path)) {
484
+			return $this;
485
+		}
486
+		if (strpos($form_section_path, '../') === 0) {
487
+			$parent = $this->parent_section();
488
+			$form_section_path = substr($form_section_path, strlen('../'));
489
+			if ($parent instanceof EE_Form_Section_Base) {
490
+				return $parent->find_section_from_path($form_section_path);
491
+			}
492
+			if (empty($form_section_path)) {
493
+				return $this;
494
+			}
495
+		}
496
+		// couldn't find it using simple parent following
497
+		return null;
498
+	}
499 499
 }
500 500
 // End of file EE_Form_Section_Base.form.php
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
         // used by display strategies
96 96
         // assign incoming values to properties
97 97
         foreach ($options_array as $key => $value) {
98
-            $key = '_' . $key;
98
+            $key = '_'.$key;
99 99
             if (property_exists($this, $key) && empty($this->{$key})) {
100 100
                 $this->{$key} = $value;
101 101
                 if ($key === '_subsections' && ! is_array($value)) {
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
      */
136 136
     public function ensure_construct_finalized_called()
137 137
     {
138
-        if (! $this->_construction_finalized) {
138
+        if ( ! $this->_construction_finalized) {
139 139
             $this->_construct_finalize($this->_parent_section, $this->_name);
140 140
         }
141 141
     }
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
      */
199 199
     protected function _set_default_html_id_if_empty()
200 200
     {
201
-        if (! $this->_html_id) {
201
+        if ( ! $this->_html_id) {
202 202
             if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
203 203
                 $this->_html_id = $this->_parent_section->html_id()
204 204
                                   . '-'
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
     public function html_id($add_pound_sign = false)
258 258
     {
259 259
         $this->_set_default_html_id_if_empty();
260
-        return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id;
260
+        return $add_pound_sign ? '#'.$this->_html_id : $this->_html_id;
261 261
     }
262 262
 
263 263
 
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
      */
328 328
     public function other_html_attributes()
329 329
     {
330
-        return ! empty($this->_other_html_attributes) ? ' ' . $this->_other_html_attributes : '';
330
+        return ! empty($this->_other_html_attributes) ? ' '.$this->_other_html_attributes : '';
331 331
     }
332 332
 
333 333
 
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
      */
341 341
     public function name()
342 342
     {
343
-        if (! $this->_construction_finalized) {
343
+        if ( ! $this->_construction_finalized) {
344 344
             throw new EE_Error(sprintf(esc_html__(
345 345
                 'You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'',
346 346
                 'event_espresso'
@@ -373,18 +373,18 @@  discard block
 block discarded – undo
373 373
      */
374 374
     public function form_open($action = '', $method = '', $other_attributes = '')
375 375
     {
376
-        if (! empty($action)) {
376
+        if ( ! empty($action)) {
377 377
             $this->set_action($action);
378 378
         }
379
-        if (! empty($method)) {
379
+        if ( ! empty($method)) {
380 380
             $this->set_method($method);
381 381
         }
382
-        $html = EEH_HTML::nl(1, 'form') . '<form';
383
-        $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : '';
384
-        $html .= ' action="' . $this->action() . '"';
385
-        $html .= ' method="' . $this->method() . '"';
386
-        $html .= ' name="' . $this->name() . '"';
387
-        $html .= $other_attributes . '>';
382
+        $html = EEH_HTML::nl(1, 'form').'<form';
383
+        $html .= $this->html_id() !== '' ? ' id="'.$this->get_html_id_for_form($this->html_id()).'"' : '';
384
+        $html .= ' action="'.$this->action().'"';
385
+        $html .= ' method="'.$this->method().'"';
386
+        $html .= ' name="'.$this->name().'"';
387
+        $html .= $other_attributes.'>';
388 388
         return $html;
389 389
     }
390 390
 
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
         $strlen = strlen($html_id);
403 403
         $html_id = strpos($html_id, '-form') === $strlen - 5 || strpos($html_id, '-frm') === $strlen - 4
404 404
             ? $html_id
405
-            : $html_id . '-frm';
405
+            : $html_id.'-frm';
406 406
         return $html_id;
407 407
     }
408 408
 
Please login to merge, or discard this patch.
core/libraries/form_sections/base/EE_Model_Form_Section.form.php 2 patches
Indentation   +456 added lines, -456 removed lines patch added patch discarded remove patch
@@ -12,460 +12,460 @@
 block discarded – undo
12 12
 class EE_Model_Form_Section extends EE_Form_Section_Proper
13 13
 {
14 14
 
15
-    /**
16
-     * @var EEM_Base
17
-     */
18
-    protected $_model = null;
19
-
20
-    /**
21
-     * @var EE_Base_Class
22
-     */
23
-    protected $_model_object = null;
24
-
25
-
26
-
27
-    /**
28
-     * @param array        $options_array   keys: {
29
-     * @type EEM_Base      $model
30
-     * @type EE_Base_Class $model_object
31
-     * @type array         $subsection_args array keys should be subsection names (that either do or will exist), and
32
-     *       values are the arrays as you would pass them to that subsection
33
-     *                                      }
34
-     * @throws EE_Error
35
-     */
36
-    public function __construct($options_array = array())
37
-    {
38
-        if (isset($options_array['model']) && $options_array['model'] instanceof EEM_Base) {
39
-            $this->_model = $options_array['model'];
40
-        }
41
-        if (! $this->_model || ! $this->_model instanceof EEM_Base) {
42
-            throw new EE_Error(sprintf(esc_html__(
43
-                "Model Form Sections must first specify the _model property to be a subclass of EEM_Base",
44
-                "event_espresso"
45
-            )));
46
-        }
47
-        if (isset($options_array['subsection_args'])) {
48
-            $subsection_args = $options_array['subsection_args'];
49
-        } else {
50
-            $subsection_args = array();
51
-        }
52
-        // gather fields and relations to convert to inputs
53
-        // but if they're just going to exclude a field anyways, don't bother converting it to an input
54
-        $exclude = $this->_subsections;
55
-        if (isset($options_array['exclude'])) {
56
-            $exclude = array_merge($exclude, array_flip($options_array['exclude']));
57
-        }
58
-        $model_fields = array_diff_key($this->_model->field_settings(), $exclude);
59
-        $model_relations = array_diff_key($this->_model->relation_settings(), $exclude);
60
-        // convert fields and relations to inputs
61
-        $this->_subsections = array_merge(
62
-            $this->_convert_model_fields_to_inputs($model_fields),
63
-            $this->_convert_model_relations_to_inputs($model_relations, $subsection_args),
64
-            $this->_subsections
65
-        );
66
-        parent::__construct($options_array);
67
-        if (isset($options_array['model_object']) && $options_array['model_object'] instanceof EE_Base_Class) {
68
-            $this->populate_model_obj($options_array['model_object']);
69
-        }
70
-    }
71
-
72
-
73
-
74
-    /**
75
-     * For now, just makes inputs for only HABTM relations
76
-     *
77
-     * @param EE_Model_Relation_Base[] $relations
78
-     * @param array                    $subsection_args keys should be existing or soon-to-be-existing input names, and
79
-     *                                                  their values are {
80
-     * @type array {
81
-     * @type EE_Base_Class[]           $model_objects   if the subsection is an EE_Select_Multi_Model_Input
82
-     *                                                  }
83
-     *                                                  }
84
-     * @return array
85
-     */
86
-    protected function _convert_model_relations_to_inputs($relations, $subsection_args = array())
87
-    {
88
-        $inputs = array();
89
-        foreach ($relations as $relation_name => $relation_obj) {
90
-            $input_constructor_args = array(
91
-                array_merge(
92
-                    array(
93
-                        'required'        => $relation_obj instanceof EE_Belongs_To_Relation,
94
-                        'html_label_text' => $relation_obj instanceof EE_Belongs_To_Relation
95
-                            ? $relation_obj->get_other_model()->item_name(1)
96
-                            : $relation_obj->get_other_model()
97
-                                           ->item_name(2),
98
-                    ),
99
-                    $subsection_args
100
-                ),
101
-            );
102
-            $input = null;
103
-            switch (get_class($relation_obj)) {
104
-                case 'EE_HABTM_Relation':
105
-                    if (
106
-                        isset($subsection_args[ $relation_name ])
107
-                        && isset($subsection_args[ $relation_name ]['model_objects'])
108
-                    ) {
109
-                        $model_objects = $subsection_args[ $relation_name ]['model_objects'];
110
-                    } else {
111
-                        $model_objects = $relation_obj->get_other_model()->get_all();
112
-                    }
113
-                    $input = new EE_Select_Multi_Model_Input($model_objects, $input_constructor_args);
114
-                    break;
115
-                default:
116
-            }
117
-            if ($input) {
118
-                $inputs[ $relation_name ] = $input;
119
-            }
120
-        }
121
-        return $inputs;
122
-    }
123
-
124
-
125
-
126
-    /**
127
-     * Changes model fields into form section inputs
128
-     *
129
-     * @param EE_Model_Field_Base[] $model_fields keys are the model's name
130
-     * @throws EE_Error
131
-     * @return EE_Form_Input_Base[]
132
-     */
133
-    protected function _convert_model_fields_to_inputs($model_fields = array())
134
-    {
135
-        $inputs = array();
136
-        foreach ($model_fields as $field_name => $model_field) {
137
-            if ($model_field instanceof EE_Model_Field_Base) {
138
-                $input_constructor_args = array(
139
-                    array(
140
-                        'required'        => ! $model_field->is_nullable()
141
-                                             && $model_field->get_default_value()
142
-                                                === null,
143
-                        'html_label_text' => $model_field->get_nicename(),
144
-                        'default'         => $model_field->get_default_value(),
145
-                    ),
146
-                );
147
-                switch (get_class($model_field)) {
148
-                    case 'EE_All_Caps_Text_Field':
149
-                    case 'EE_Any_Foreign_Model_Name_Field':
150
-                        $input_class = 'EE_Text_Input';
151
-                        break;
152
-                    case 'EE_Boolean_Field':
153
-                        $input_class = 'EE_Yes_No_Input';
154
-                        break;
155
-                    case 'EE_Datetime_Field':
156
-                        throw new EE_Error(sprintf(esc_html__(
157
-                            "Model field '%s' does not yet have a known conversion to form input",
158
-                            "event_espresso"
159
-                        ), get_class($model_field)));
160
-                        break;
161
-                    case 'EE_Email_Field':
162
-                        $input_class = 'EE_Email_Input';
163
-                        break;
164
-                    case 'EE_Enum_Integer_Field':
165
-                        throw new EE_Error(sprintf(esc_html__(
166
-                            "Model field '%s' does not yet have a known conversion to form input",
167
-                            "event_espresso"
168
-                        ), get_class($model_field)));
169
-                        break;
170
-                    case 'EE_Enum_Text_Field':
171
-                        throw new EE_Error(sprintf(esc_html__(
172
-                            "Model field '%s' does not yet have a known conversion to form input",
173
-                            "event_espresso"
174
-                        ), get_class($model_field)));
175
-                        break;
176
-                    case 'EE_Float_Field':
177
-                        $input_class = 'EE_Float_Input';
178
-                        break;
179
-                    case 'EE_Foreign_Key_Int_Field':
180
-                    case 'EE_Foreign_Key_String_Field':
181
-                    case 'EE_WP_User_Field':
182
-                        $models_pointed_to = $model_field instanceof EE_Field_With_Model_Name
183
-                            ? $model_field->get_model_class_names_pointed_to() : array();
184
-                        if (true || is_array($models_pointed_to) && count($models_pointed_to) > 1) {
185
-                            $input_class = 'EE_Text_Input';
186
-                        } else {
187
-                            // so its just one model
188
-                            $model_name = is_array($models_pointed_to) ? reset($models_pointed_to) : $models_pointed_to;
189
-                            $model = EE_Registry::instance()->load_model($model_name);
190
-                            $model_names = $model->get_all_names(array('limit' => 10));
191
-                            if ($model_field->is_nullable()) {
192
-                                array_unshift($model_names, esc_html__("Please Select", 'event_espresso'));
193
-                            }
194
-                            $input_constructor_args[1] = $input_constructor_args[0];
195
-                            $input_constructor_args[0] = $model_names;
196
-                            $input_class = 'EE_Select_Input';
197
-                        }
198
-                        break;
199
-                    case 'EE_Full_HTML_Field':
200
-                        $input_class = 'EE_Text_Area_Input';
201
-                        $input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy());
202
-                        break;
203
-                    case 'EE_Infinite_Integer':
204
-                        throw new EE_Error(sprintf(esc_html__(
205
-                            "Model field '%s' does not yet have a known conversion to form input",
206
-                            "event_espresso"
207
-                        ), get_class($model_field)));
208
-                        break;
209
-                    case 'EE_Integer_Field':
210
-                        $input_class = 'EE_Text_Input';
211
-                        break;
212
-                    case 'EE_Maybe_Serialized_Text_Field':
213
-                        $input_class = 'EE_Text_Area_Input';
214
-                        break;
215
-                    case 'EE_Money_Field':
216
-                        throw new EE_Error(sprintf(esc_html__(
217
-                            "Model field '%s' does not yet have a known conversion to form input",
218
-                            "event_espresso"
219
-                        ), get_class($model_field)));
220
-                        break;
221
-                    case 'EE_Post_Content_Field':
222
-                        $input_class = 'EE_Text_Area_Input';
223
-                        $input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy());
224
-                        break;
225
-                    case 'EE_Plain_Text_Field':
226
-                        $input_class = 'EE_Text_Input';
227
-                        break;
228
-                    case 'EE_Primary_Key_Int_Field':
229
-                        $input_class = 'EE_Hidden_Input';
230
-                        $input_constructor_args[0]['normalization_strategy'] = new EE_Int_Normalization();
231
-                        break;
232
-                    case 'EE_Primary_Key_String_Field':
233
-                        $input_class = 'EE_Hidden_Input';
234
-                        break;
235
-                    case 'EE_Serialized_Text_Field':
236
-                        $input_class = 'EE_Text_Area_Input';
237
-                        break;
238
-                    case 'EE_Simple_HTML_Field':
239
-                        $input_class = 'EE_Text_Area_Input';
240
-                        $input_constructor_args[0]['validation_strategies'] = array(new EE_Simple_HTML_Validation_Strategy());
241
-                        break;
242
-                    case 'EE_Slug_Field':
243
-                        $input_class = 'EE_Text_Input';
244
-                        break;
245
-                    case 'EE_Trashed_Flag_Field':
246
-                        $input_class = 'EE_Yes_No_Input';
247
-                        break;
248
-                    case 'EE_WP_Post_Status_Field':
249
-                        throw new EE_Error(sprintf(esc_html__(
250
-                            "Model field '%s' does not yet have a known conversion to form input",
251
-                            "event_espresso"
252
-                        ), get_class($model_field)));
253
-                        break;
254
-                    case 'EE_WP_Post_Type_Field':
255
-                        throw new EE_Error(sprintf(esc_html__(
256
-                            "Model field '%s' does not yet have a known conversion to form input",
257
-                            "event_espresso"
258
-                        ), get_class($model_field)));
259
-                        break;
260
-                    default:
261
-                        throw new EE_Error(sprintf(esc_html__(
262
-                            "Model field of type '%s' does not convert to any known Form Input. Please add a case to EE_Model_Form_section's _convert_model_fields_to_inputs switch statement",
263
-                            "event_espresso"
264
-                        ), get_class($model_field)));
265
-                }
266
-                $reflection = new ReflectionClass($input_class);
267
-                $input = $reflection->newInstanceArgs($input_constructor_args);
268
-                $inputs[ $field_name ] = $input;
269
-            }
270
-        }
271
-        return $inputs;
272
-    }
273
-
274
-
275
-
276
-    /**
277
-     * Mostly the same as populate_defaults , except takes a model object as input, not an array,
278
-     * and also sets the form's _model_object
279
-     *
280
-     * @param EE_Base_Class $model_obj
281
-     * @return void
282
-     */
283
-    public function populate_model_obj($model_obj)
284
-    {
285
-        $model_obj = $this->_model->ensure_is_obj($model_obj);
286
-        $this->_model_object = $model_obj;
287
-        $defaults = $model_obj->model_field_array();
288
-        foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) {
289
-            $subsection = $this->get_subsection($relation_name, false);
290
-            if ($subsection instanceof EE_Form_Input_Base) {
291
-                if ($relation_obj instanceof EE_Belongs_To_Relation) {
292
-                    // then we only expect there to be one
293
-                    $related_item = $this->_model_object->get_first_related($relation_name);
294
-                    $defaults[ $relation_name ] = $related_item->ID();
295
-                } else {
296
-                    $related_items = $this->_model_object->get_many_related($relation_name);
297
-                    $ids = array();
298
-                    foreach ($related_items as $related_item) {
299
-                        $ids[] = $related_item->ID();
300
-                    }
301
-                    $defaults[ $relation_name ] = $ids;
302
-                }
303
-            }
304
-        }
305
-        $defaults = apply_filters(
306
-            'FHEE__EE_Model_Form_Section__populate_model_obj',
307
-            $defaults,
308
-            $this
309
-        );
310
-        $this->populate_defaults($defaults);
311
-    }
312
-
313
-
314
-
315
-    /**
316
-     * Gets all the input values that correspond to model fields. Keys are the input/field names,
317
-     * values are their normalized values
318
-     *
319
-     * @return array
320
-     */
321
-    public function inputs_values_corresponding_to_model_fields()
322
-    {
323
-        return array_intersect_key($this->input_values(), $this->_model->field_settings());
324
-    }
325
-
326
-
327
-
328
-    /**
329
-     * After we've normalized the data as normal, set the corresponding model object
330
-     * on the form.
331
-     *
332
-     * @param array $req_data should usually be the form post/request data (the default).
333
-     * @return void
334
-     */
335
-    public function _normalize($req_data)
336
-    {
337
-        parent::_normalize($req_data);
338
-        // create or set the model object, if it isn't already
339
-        if (! $this->_model_object) {
340
-            // check to see if the form indicates a PK, in which case we want to only retrieve it and update it
341
-            $pk_name = $this->_model->primary_key_name();
342
-            $model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name));
343
-            if ($model_obj) {
344
-                $this->_model_object = $model_obj;
345
-            } else {
346
-                $this->_model_object = EE_Registry::instance()->load_class($this->_model->get_this_model_name());
347
-            }
348
-        }
349
-    }
350
-
351
-
352
-
353
-    /**
354
-     * After this form has been initialized and is verified to be valid,
355
-     * either creates a model object from its data and saves it, or updates
356
-     * the model object its data represents
357
-     *
358
-     * @throws EE_Error
359
-     * @return int, 1 on a successful update, the ID of
360
-     *                    the new entry on insert; 0 on failure
361
-     */
362
-    public function save()
363
-    {
364
-        if (! $this->_model_object) {
365
-            throw new EE_Error(sprintf(esc_html__(
366
-                "Cannot save the model form's model object (model is '%s') because there is no model object set. You must either set it, or call receive_form_submission where it is set automatically",
367
-                "event_espresso"
368
-            ), get_class($this->_model)));
369
-        }
370
-        // ok so the model object is set. Just set it with the submitted form data
371
-        foreach ($this->inputs_values_corresponding_to_model_fields() as $field_name => $field_value) {
372
-            // only set the non-primary key
373
-            if ($field_name != $this->_model->primary_key_name()) {
374
-                $this->_model_object->set($field_name, $field_value);
375
-            }
376
-        }
377
-        $success = $this->_model_object->save();
378
-        foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) {
379
-            if (isset($this->_subsections[ $relation_name ])) {
380
-                $success = $this->_save_related_info($relation_name);
381
-            }
382
-        }
383
-        do_action('AHEE__EE_Model_Form_Section__save__done', $this, $success);
384
-        return $success;
385
-    }
386
-
387
-
388
-
389
-    /**
390
-     * Automatically finds the related model info from the form, if present, and
391
-     * save the relations indicated
392
-     *
393
-     * @type string $relation_name
394
-     * @return bool
395
-     * @throws EE_Error
396
-     */
397
-    protected function _save_related_info($relation_name)
398
-    {
399
-        $relation_obj = $this->_model->related_settings_for($relation_name);
400
-        if ($relation_obj instanceof EE_Belongs_To_Relation) {
401
-            // there is just a foreign key on this model pointing to that one
402
-            $this->_model_object->_add_relation_to($this->get_input_value($relation_name), $relation_name);
403
-        } elseif ($relation_obj instanceof EE_Has_Many_Relation) {
404
-            // then we want to consider all of its currently-related things.
405
-            // if they're in this list, keep them
406
-            // if they're not in this list, remove them
407
-            // and lastly add all the new items
408
-            throw new EE_Error(sprintf(esc_html__(
409
-                'Automatic saving of related info across a "has many" relation is not yet supported',
410
-                "event_espresso"
411
-            )));
412
-        } elseif ($relation_obj instanceof EE_HABTM_Relation) {
413
-            // delete everything NOT in this list
414
-            $normalized_input_value = $this->get_input_value($relation_name);
415
-            if ($normalized_input_value && is_array($normalized_input_value)) {
416
-                $where_query_params = array(
417
-                    $relation_obj->get_other_model()->primary_key_name() => array('NOT_IN', $normalized_input_value),
418
-                );
419
-            } else {
420
-                $where_query_params = array();
421
-            }
422
-            $this->_model_object->_remove_relations($relation_name, $where_query_params);
423
-            foreach ($normalized_input_value as $id) {
424
-                $this->_model_object->_add_relation_to($id, $relation_name);
425
-            }
426
-        }
427
-        return true;
428
-    }
429
-
430
-
431
-
432
-    /**
433
-     * Gets the model of this model form
434
-     *
435
-     * @return EEM_Base
436
-     */
437
-    public function get_model()
438
-    {
439
-        return $this->_model;
440
-    }
441
-
442
-
443
-
444
-    /**
445
-     * Gets the model object for this model form, which was either set
446
-     * upon construction (using the $options_array arg 'model_object'), by using
447
-     * set_model_object($model_obj), or implicitly
448
-     * when receive_form_submission($req_data) was called.
449
-     *
450
-     * @return EE_Base_Class
451
-     */
452
-    public function get_model_object()
453
-    {
454
-        return $this->_model_object;
455
-    }
456
-
457
-
458
-
459
-    /**
460
-     * gets teh default name of this form section if none is specified
461
-     *
462
-     * @return string
463
-     */
464
-    protected function _set_default_name_if_empty()
465
-    {
466
-        if (! $this->_name) {
467
-            $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form";
468
-            $this->_name = $default_name;
469
-        }
470
-    }
15
+	/**
16
+	 * @var EEM_Base
17
+	 */
18
+	protected $_model = null;
19
+
20
+	/**
21
+	 * @var EE_Base_Class
22
+	 */
23
+	protected $_model_object = null;
24
+
25
+
26
+
27
+	/**
28
+	 * @param array        $options_array   keys: {
29
+	 * @type EEM_Base      $model
30
+	 * @type EE_Base_Class $model_object
31
+	 * @type array         $subsection_args array keys should be subsection names (that either do or will exist), and
32
+	 *       values are the arrays as you would pass them to that subsection
33
+	 *                                      }
34
+	 * @throws EE_Error
35
+	 */
36
+	public function __construct($options_array = array())
37
+	{
38
+		if (isset($options_array['model']) && $options_array['model'] instanceof EEM_Base) {
39
+			$this->_model = $options_array['model'];
40
+		}
41
+		if (! $this->_model || ! $this->_model instanceof EEM_Base) {
42
+			throw new EE_Error(sprintf(esc_html__(
43
+				"Model Form Sections must first specify the _model property to be a subclass of EEM_Base",
44
+				"event_espresso"
45
+			)));
46
+		}
47
+		if (isset($options_array['subsection_args'])) {
48
+			$subsection_args = $options_array['subsection_args'];
49
+		} else {
50
+			$subsection_args = array();
51
+		}
52
+		// gather fields and relations to convert to inputs
53
+		// but if they're just going to exclude a field anyways, don't bother converting it to an input
54
+		$exclude = $this->_subsections;
55
+		if (isset($options_array['exclude'])) {
56
+			$exclude = array_merge($exclude, array_flip($options_array['exclude']));
57
+		}
58
+		$model_fields = array_diff_key($this->_model->field_settings(), $exclude);
59
+		$model_relations = array_diff_key($this->_model->relation_settings(), $exclude);
60
+		// convert fields and relations to inputs
61
+		$this->_subsections = array_merge(
62
+			$this->_convert_model_fields_to_inputs($model_fields),
63
+			$this->_convert_model_relations_to_inputs($model_relations, $subsection_args),
64
+			$this->_subsections
65
+		);
66
+		parent::__construct($options_array);
67
+		if (isset($options_array['model_object']) && $options_array['model_object'] instanceof EE_Base_Class) {
68
+			$this->populate_model_obj($options_array['model_object']);
69
+		}
70
+	}
71
+
72
+
73
+
74
+	/**
75
+	 * For now, just makes inputs for only HABTM relations
76
+	 *
77
+	 * @param EE_Model_Relation_Base[] $relations
78
+	 * @param array                    $subsection_args keys should be existing or soon-to-be-existing input names, and
79
+	 *                                                  their values are {
80
+	 * @type array {
81
+	 * @type EE_Base_Class[]           $model_objects   if the subsection is an EE_Select_Multi_Model_Input
82
+	 *                                                  }
83
+	 *                                                  }
84
+	 * @return array
85
+	 */
86
+	protected function _convert_model_relations_to_inputs($relations, $subsection_args = array())
87
+	{
88
+		$inputs = array();
89
+		foreach ($relations as $relation_name => $relation_obj) {
90
+			$input_constructor_args = array(
91
+				array_merge(
92
+					array(
93
+						'required'        => $relation_obj instanceof EE_Belongs_To_Relation,
94
+						'html_label_text' => $relation_obj instanceof EE_Belongs_To_Relation
95
+							? $relation_obj->get_other_model()->item_name(1)
96
+							: $relation_obj->get_other_model()
97
+										   ->item_name(2),
98
+					),
99
+					$subsection_args
100
+				),
101
+			);
102
+			$input = null;
103
+			switch (get_class($relation_obj)) {
104
+				case 'EE_HABTM_Relation':
105
+					if (
106
+						isset($subsection_args[ $relation_name ])
107
+						&& isset($subsection_args[ $relation_name ]['model_objects'])
108
+					) {
109
+						$model_objects = $subsection_args[ $relation_name ]['model_objects'];
110
+					} else {
111
+						$model_objects = $relation_obj->get_other_model()->get_all();
112
+					}
113
+					$input = new EE_Select_Multi_Model_Input($model_objects, $input_constructor_args);
114
+					break;
115
+				default:
116
+			}
117
+			if ($input) {
118
+				$inputs[ $relation_name ] = $input;
119
+			}
120
+		}
121
+		return $inputs;
122
+	}
123
+
124
+
125
+
126
+	/**
127
+	 * Changes model fields into form section inputs
128
+	 *
129
+	 * @param EE_Model_Field_Base[] $model_fields keys are the model's name
130
+	 * @throws EE_Error
131
+	 * @return EE_Form_Input_Base[]
132
+	 */
133
+	protected function _convert_model_fields_to_inputs($model_fields = array())
134
+	{
135
+		$inputs = array();
136
+		foreach ($model_fields as $field_name => $model_field) {
137
+			if ($model_field instanceof EE_Model_Field_Base) {
138
+				$input_constructor_args = array(
139
+					array(
140
+						'required'        => ! $model_field->is_nullable()
141
+											 && $model_field->get_default_value()
142
+												=== null,
143
+						'html_label_text' => $model_field->get_nicename(),
144
+						'default'         => $model_field->get_default_value(),
145
+					),
146
+				);
147
+				switch (get_class($model_field)) {
148
+					case 'EE_All_Caps_Text_Field':
149
+					case 'EE_Any_Foreign_Model_Name_Field':
150
+						$input_class = 'EE_Text_Input';
151
+						break;
152
+					case 'EE_Boolean_Field':
153
+						$input_class = 'EE_Yes_No_Input';
154
+						break;
155
+					case 'EE_Datetime_Field':
156
+						throw new EE_Error(sprintf(esc_html__(
157
+							"Model field '%s' does not yet have a known conversion to form input",
158
+							"event_espresso"
159
+						), get_class($model_field)));
160
+						break;
161
+					case 'EE_Email_Field':
162
+						$input_class = 'EE_Email_Input';
163
+						break;
164
+					case 'EE_Enum_Integer_Field':
165
+						throw new EE_Error(sprintf(esc_html__(
166
+							"Model field '%s' does not yet have a known conversion to form input",
167
+							"event_espresso"
168
+						), get_class($model_field)));
169
+						break;
170
+					case 'EE_Enum_Text_Field':
171
+						throw new EE_Error(sprintf(esc_html__(
172
+							"Model field '%s' does not yet have a known conversion to form input",
173
+							"event_espresso"
174
+						), get_class($model_field)));
175
+						break;
176
+					case 'EE_Float_Field':
177
+						$input_class = 'EE_Float_Input';
178
+						break;
179
+					case 'EE_Foreign_Key_Int_Field':
180
+					case 'EE_Foreign_Key_String_Field':
181
+					case 'EE_WP_User_Field':
182
+						$models_pointed_to = $model_field instanceof EE_Field_With_Model_Name
183
+							? $model_field->get_model_class_names_pointed_to() : array();
184
+						if (true || is_array($models_pointed_to) && count($models_pointed_to) > 1) {
185
+							$input_class = 'EE_Text_Input';
186
+						} else {
187
+							// so its just one model
188
+							$model_name = is_array($models_pointed_to) ? reset($models_pointed_to) : $models_pointed_to;
189
+							$model = EE_Registry::instance()->load_model($model_name);
190
+							$model_names = $model->get_all_names(array('limit' => 10));
191
+							if ($model_field->is_nullable()) {
192
+								array_unshift($model_names, esc_html__("Please Select", 'event_espresso'));
193
+							}
194
+							$input_constructor_args[1] = $input_constructor_args[0];
195
+							$input_constructor_args[0] = $model_names;
196
+							$input_class = 'EE_Select_Input';
197
+						}
198
+						break;
199
+					case 'EE_Full_HTML_Field':
200
+						$input_class = 'EE_Text_Area_Input';
201
+						$input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy());
202
+						break;
203
+					case 'EE_Infinite_Integer':
204
+						throw new EE_Error(sprintf(esc_html__(
205
+							"Model field '%s' does not yet have a known conversion to form input",
206
+							"event_espresso"
207
+						), get_class($model_field)));
208
+						break;
209
+					case 'EE_Integer_Field':
210
+						$input_class = 'EE_Text_Input';
211
+						break;
212
+					case 'EE_Maybe_Serialized_Text_Field':
213
+						$input_class = 'EE_Text_Area_Input';
214
+						break;
215
+					case 'EE_Money_Field':
216
+						throw new EE_Error(sprintf(esc_html__(
217
+							"Model field '%s' does not yet have a known conversion to form input",
218
+							"event_espresso"
219
+						), get_class($model_field)));
220
+						break;
221
+					case 'EE_Post_Content_Field':
222
+						$input_class = 'EE_Text_Area_Input';
223
+						$input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy());
224
+						break;
225
+					case 'EE_Plain_Text_Field':
226
+						$input_class = 'EE_Text_Input';
227
+						break;
228
+					case 'EE_Primary_Key_Int_Field':
229
+						$input_class = 'EE_Hidden_Input';
230
+						$input_constructor_args[0]['normalization_strategy'] = new EE_Int_Normalization();
231
+						break;
232
+					case 'EE_Primary_Key_String_Field':
233
+						$input_class = 'EE_Hidden_Input';
234
+						break;
235
+					case 'EE_Serialized_Text_Field':
236
+						$input_class = 'EE_Text_Area_Input';
237
+						break;
238
+					case 'EE_Simple_HTML_Field':
239
+						$input_class = 'EE_Text_Area_Input';
240
+						$input_constructor_args[0]['validation_strategies'] = array(new EE_Simple_HTML_Validation_Strategy());
241
+						break;
242
+					case 'EE_Slug_Field':
243
+						$input_class = 'EE_Text_Input';
244
+						break;
245
+					case 'EE_Trashed_Flag_Field':
246
+						$input_class = 'EE_Yes_No_Input';
247
+						break;
248
+					case 'EE_WP_Post_Status_Field':
249
+						throw new EE_Error(sprintf(esc_html__(
250
+							"Model field '%s' does not yet have a known conversion to form input",
251
+							"event_espresso"
252
+						), get_class($model_field)));
253
+						break;
254
+					case 'EE_WP_Post_Type_Field':
255
+						throw new EE_Error(sprintf(esc_html__(
256
+							"Model field '%s' does not yet have a known conversion to form input",
257
+							"event_espresso"
258
+						), get_class($model_field)));
259
+						break;
260
+					default:
261
+						throw new EE_Error(sprintf(esc_html__(
262
+							"Model field of type '%s' does not convert to any known Form Input. Please add a case to EE_Model_Form_section's _convert_model_fields_to_inputs switch statement",
263
+							"event_espresso"
264
+						), get_class($model_field)));
265
+				}
266
+				$reflection = new ReflectionClass($input_class);
267
+				$input = $reflection->newInstanceArgs($input_constructor_args);
268
+				$inputs[ $field_name ] = $input;
269
+			}
270
+		}
271
+		return $inputs;
272
+	}
273
+
274
+
275
+
276
+	/**
277
+	 * Mostly the same as populate_defaults , except takes a model object as input, not an array,
278
+	 * and also sets the form's _model_object
279
+	 *
280
+	 * @param EE_Base_Class $model_obj
281
+	 * @return void
282
+	 */
283
+	public function populate_model_obj($model_obj)
284
+	{
285
+		$model_obj = $this->_model->ensure_is_obj($model_obj);
286
+		$this->_model_object = $model_obj;
287
+		$defaults = $model_obj->model_field_array();
288
+		foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) {
289
+			$subsection = $this->get_subsection($relation_name, false);
290
+			if ($subsection instanceof EE_Form_Input_Base) {
291
+				if ($relation_obj instanceof EE_Belongs_To_Relation) {
292
+					// then we only expect there to be one
293
+					$related_item = $this->_model_object->get_first_related($relation_name);
294
+					$defaults[ $relation_name ] = $related_item->ID();
295
+				} else {
296
+					$related_items = $this->_model_object->get_many_related($relation_name);
297
+					$ids = array();
298
+					foreach ($related_items as $related_item) {
299
+						$ids[] = $related_item->ID();
300
+					}
301
+					$defaults[ $relation_name ] = $ids;
302
+				}
303
+			}
304
+		}
305
+		$defaults = apply_filters(
306
+			'FHEE__EE_Model_Form_Section__populate_model_obj',
307
+			$defaults,
308
+			$this
309
+		);
310
+		$this->populate_defaults($defaults);
311
+	}
312
+
313
+
314
+
315
+	/**
316
+	 * Gets all the input values that correspond to model fields. Keys are the input/field names,
317
+	 * values are their normalized values
318
+	 *
319
+	 * @return array
320
+	 */
321
+	public function inputs_values_corresponding_to_model_fields()
322
+	{
323
+		return array_intersect_key($this->input_values(), $this->_model->field_settings());
324
+	}
325
+
326
+
327
+
328
+	/**
329
+	 * After we've normalized the data as normal, set the corresponding model object
330
+	 * on the form.
331
+	 *
332
+	 * @param array $req_data should usually be the form post/request data (the default).
333
+	 * @return void
334
+	 */
335
+	public function _normalize($req_data)
336
+	{
337
+		parent::_normalize($req_data);
338
+		// create or set the model object, if it isn't already
339
+		if (! $this->_model_object) {
340
+			// check to see if the form indicates a PK, in which case we want to only retrieve it and update it
341
+			$pk_name = $this->_model->primary_key_name();
342
+			$model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name));
343
+			if ($model_obj) {
344
+				$this->_model_object = $model_obj;
345
+			} else {
346
+				$this->_model_object = EE_Registry::instance()->load_class($this->_model->get_this_model_name());
347
+			}
348
+		}
349
+	}
350
+
351
+
352
+
353
+	/**
354
+	 * After this form has been initialized and is verified to be valid,
355
+	 * either creates a model object from its data and saves it, or updates
356
+	 * the model object its data represents
357
+	 *
358
+	 * @throws EE_Error
359
+	 * @return int, 1 on a successful update, the ID of
360
+	 *                    the new entry on insert; 0 on failure
361
+	 */
362
+	public function save()
363
+	{
364
+		if (! $this->_model_object) {
365
+			throw new EE_Error(sprintf(esc_html__(
366
+				"Cannot save the model form's model object (model is '%s') because there is no model object set. You must either set it, or call receive_form_submission where it is set automatically",
367
+				"event_espresso"
368
+			), get_class($this->_model)));
369
+		}
370
+		// ok so the model object is set. Just set it with the submitted form data
371
+		foreach ($this->inputs_values_corresponding_to_model_fields() as $field_name => $field_value) {
372
+			// only set the non-primary key
373
+			if ($field_name != $this->_model->primary_key_name()) {
374
+				$this->_model_object->set($field_name, $field_value);
375
+			}
376
+		}
377
+		$success = $this->_model_object->save();
378
+		foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) {
379
+			if (isset($this->_subsections[ $relation_name ])) {
380
+				$success = $this->_save_related_info($relation_name);
381
+			}
382
+		}
383
+		do_action('AHEE__EE_Model_Form_Section__save__done', $this, $success);
384
+		return $success;
385
+	}
386
+
387
+
388
+
389
+	/**
390
+	 * Automatically finds the related model info from the form, if present, and
391
+	 * save the relations indicated
392
+	 *
393
+	 * @type string $relation_name
394
+	 * @return bool
395
+	 * @throws EE_Error
396
+	 */
397
+	protected function _save_related_info($relation_name)
398
+	{
399
+		$relation_obj = $this->_model->related_settings_for($relation_name);
400
+		if ($relation_obj instanceof EE_Belongs_To_Relation) {
401
+			// there is just a foreign key on this model pointing to that one
402
+			$this->_model_object->_add_relation_to($this->get_input_value($relation_name), $relation_name);
403
+		} elseif ($relation_obj instanceof EE_Has_Many_Relation) {
404
+			// then we want to consider all of its currently-related things.
405
+			// if they're in this list, keep them
406
+			// if they're not in this list, remove them
407
+			// and lastly add all the new items
408
+			throw new EE_Error(sprintf(esc_html__(
409
+				'Automatic saving of related info across a "has many" relation is not yet supported',
410
+				"event_espresso"
411
+			)));
412
+		} elseif ($relation_obj instanceof EE_HABTM_Relation) {
413
+			// delete everything NOT in this list
414
+			$normalized_input_value = $this->get_input_value($relation_name);
415
+			if ($normalized_input_value && is_array($normalized_input_value)) {
416
+				$where_query_params = array(
417
+					$relation_obj->get_other_model()->primary_key_name() => array('NOT_IN', $normalized_input_value),
418
+				);
419
+			} else {
420
+				$where_query_params = array();
421
+			}
422
+			$this->_model_object->_remove_relations($relation_name, $where_query_params);
423
+			foreach ($normalized_input_value as $id) {
424
+				$this->_model_object->_add_relation_to($id, $relation_name);
425
+			}
426
+		}
427
+		return true;
428
+	}
429
+
430
+
431
+
432
+	/**
433
+	 * Gets the model of this model form
434
+	 *
435
+	 * @return EEM_Base
436
+	 */
437
+	public function get_model()
438
+	{
439
+		return $this->_model;
440
+	}
441
+
442
+
443
+
444
+	/**
445
+	 * Gets the model object for this model form, which was either set
446
+	 * upon construction (using the $options_array arg 'model_object'), by using
447
+	 * set_model_object($model_obj), or implicitly
448
+	 * when receive_form_submission($req_data) was called.
449
+	 *
450
+	 * @return EE_Base_Class
451
+	 */
452
+	public function get_model_object()
453
+	{
454
+		return $this->_model_object;
455
+	}
456
+
457
+
458
+
459
+	/**
460
+	 * gets teh default name of this form section if none is specified
461
+	 *
462
+	 * @return string
463
+	 */
464
+	protected function _set_default_name_if_empty()
465
+	{
466
+		if (! $this->_name) {
467
+			$default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form";
468
+			$this->_name = $default_name;
469
+		}
470
+	}
471 471
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
         if (isset($options_array['model']) && $options_array['model'] instanceof EEM_Base) {
39 39
             $this->_model = $options_array['model'];
40 40
         }
41
-        if (! $this->_model || ! $this->_model instanceof EEM_Base) {
41
+        if ( ! $this->_model || ! $this->_model instanceof EEM_Base) {
42 42
             throw new EE_Error(sprintf(esc_html__(
43 43
                 "Model Form Sections must first specify the _model property to be a subclass of EEM_Base",
44 44
                 "event_espresso"
@@ -103,10 +103,10 @@  discard block
 block discarded – undo
103 103
             switch (get_class($relation_obj)) {
104 104
                 case 'EE_HABTM_Relation':
105 105
                     if (
106
-                        isset($subsection_args[ $relation_name ])
107
-                        && isset($subsection_args[ $relation_name ]['model_objects'])
106
+                        isset($subsection_args[$relation_name])
107
+                        && isset($subsection_args[$relation_name]['model_objects'])
108 108
                     ) {
109
-                        $model_objects = $subsection_args[ $relation_name ]['model_objects'];
109
+                        $model_objects = $subsection_args[$relation_name]['model_objects'];
110 110
                     } else {
111 111
                         $model_objects = $relation_obj->get_other_model()->get_all();
112 112
                     }
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
                 default:
116 116
             }
117 117
             if ($input) {
118
-                $inputs[ $relation_name ] = $input;
118
+                $inputs[$relation_name] = $input;
119 119
             }
120 120
         }
121 121
         return $inputs;
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
                 }
266 266
                 $reflection = new ReflectionClass($input_class);
267 267
                 $input = $reflection->newInstanceArgs($input_constructor_args);
268
-                $inputs[ $field_name ] = $input;
268
+                $inputs[$field_name] = $input;
269 269
             }
270 270
         }
271 271
         return $inputs;
@@ -291,14 +291,14 @@  discard block
 block discarded – undo
291 291
                 if ($relation_obj instanceof EE_Belongs_To_Relation) {
292 292
                     // then we only expect there to be one
293 293
                     $related_item = $this->_model_object->get_first_related($relation_name);
294
-                    $defaults[ $relation_name ] = $related_item->ID();
294
+                    $defaults[$relation_name] = $related_item->ID();
295 295
                 } else {
296 296
                     $related_items = $this->_model_object->get_many_related($relation_name);
297 297
                     $ids = array();
298 298
                     foreach ($related_items as $related_item) {
299 299
                         $ids[] = $related_item->ID();
300 300
                     }
301
-                    $defaults[ $relation_name ] = $ids;
301
+                    $defaults[$relation_name] = $ids;
302 302
                 }
303 303
             }
304 304
         }
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
     {
337 337
         parent::_normalize($req_data);
338 338
         // create or set the model object, if it isn't already
339
-        if (! $this->_model_object) {
339
+        if ( ! $this->_model_object) {
340 340
             // check to see if the form indicates a PK, in which case we want to only retrieve it and update it
341 341
             $pk_name = $this->_model->primary_key_name();
342 342
             $model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name));
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
      */
362 362
     public function save()
363 363
     {
364
-        if (! $this->_model_object) {
364
+        if ( ! $this->_model_object) {
365 365
             throw new EE_Error(sprintf(esc_html__(
366 366
                 "Cannot save the model form's model object (model is '%s') because there is no model object set. You must either set it, or call receive_form_submission where it is set automatically",
367 367
                 "event_espresso"
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
         }
377 377
         $success = $this->_model_object->save();
378 378
         foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) {
379
-            if (isset($this->_subsections[ $relation_name ])) {
379
+            if (isset($this->_subsections[$relation_name])) {
380 380
                 $success = $this->_save_related_info($relation_name);
381 381
             }
382 382
         }
@@ -463,8 +463,8 @@  discard block
 block discarded – undo
463 463
      */
464 464
     protected function _set_default_name_if_empty()
465 465
     {
466
-        if (! $this->_name) {
467
-            $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form";
466
+        if ( ! $this->_name) {
467
+            $default_name = str_replace("EEM_", "", get_class($this->_model))."_Model_Form";
468 468
             $this->_name = $default_name;
469 469
         }
470 470
     }
Please login to merge, or discard this patch.
core/libraries/form_sections/EE_Sample_Form.form.php 2 patches
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -2,62 +2,62 @@
 block discarded – undo
2 2
 
3 3
 class EE_Sample_Form extends EE_Form_Section_Proper
4 4
 {
5
-    public function __construct()
6
-    {
7
-        $this->_subsections = array(
8
-            'h1' => new EE_Form_Section_HTML('hello wordl'),
9
-            'name' => new EE_Text_Input(array('required' => true,'default' => 'your name here')),
10
-            'email' => new EE_Email_Input(array('required' => false)),
11
-            'shirt_size' => new EE_Select_Input(array('' => 'Please select...', 's' =>  esc_html__("Small", "event_espresso"),'m' =>  esc_html__("Medium", "event_espresso"),'l' =>  esc_html__("Large", "event_espresso")), array('required' => true,'default' => 's')),
12
-            'month_normal' => new EE_Month_Input(),
13
-            'month_leading_zero' => new EE_Month_Input(true),
14
-            'year_2' => new EE_Year_Input(false, 1, 1),
15
-            'year_4' => new EE_Year_Input(true, 0, 10, array('default' => '2017')),
16
-            'yes_no' => new EE_Yes_No_Input(array('html_label_text' =>  esc_html__("Yes or No", "event_espresso"))),
17
-            'credit_card' => new EE_Credit_Card_Input(),
18
-            'image_1' => new EE_Admin_File_Uploader_Input(),
19
-            'image_2' => new EE_Admin_File_Uploader_Input(),
20
-            'skillz' => new EE_Checkbox_Multi_Input(array('php' => 'PHP','mysql' => 'MYSQL'), array('default' => array('php'))),
21
-            'float' => new EE_Float_Input(),
22
-            'essay' => new EE_Text_Area_Input(),
23
-            'amenities' => new EE_Select_Multiple_Input(
24
-                array(
25
-                    'hottub' => 'Hot Tub',
26
-                    'balcony' => "Balcony",
27
-                    'skylight' => 'SkyLight',
28
-                    'no_axe' => 'No Axe Murderers'
29
-                ),
30
-                array(
31
-                    'default' => array(
32
-                        'hottub',
33
-                        'no_axe' ),
34
-                )
35
-            ),
36
-            'payment_methods' => new EE_Select_Multi_Model_Input(EEM_Payment_Method::instance()->get_all()),
37
-            );
38
-        $this->_layout_strategy = new EE_Div_Per_Section_Layout();
39
-        parent::__construct();
40
-    }
5
+	public function __construct()
6
+	{
7
+		$this->_subsections = array(
8
+			'h1' => new EE_Form_Section_HTML('hello wordl'),
9
+			'name' => new EE_Text_Input(array('required' => true,'default' => 'your name here')),
10
+			'email' => new EE_Email_Input(array('required' => false)),
11
+			'shirt_size' => new EE_Select_Input(array('' => 'Please select...', 's' =>  esc_html__("Small", "event_espresso"),'m' =>  esc_html__("Medium", "event_espresso"),'l' =>  esc_html__("Large", "event_espresso")), array('required' => true,'default' => 's')),
12
+			'month_normal' => new EE_Month_Input(),
13
+			'month_leading_zero' => new EE_Month_Input(true),
14
+			'year_2' => new EE_Year_Input(false, 1, 1),
15
+			'year_4' => new EE_Year_Input(true, 0, 10, array('default' => '2017')),
16
+			'yes_no' => new EE_Yes_No_Input(array('html_label_text' =>  esc_html__("Yes or No", "event_espresso"))),
17
+			'credit_card' => new EE_Credit_Card_Input(),
18
+			'image_1' => new EE_Admin_File_Uploader_Input(),
19
+			'image_2' => new EE_Admin_File_Uploader_Input(),
20
+			'skillz' => new EE_Checkbox_Multi_Input(array('php' => 'PHP','mysql' => 'MYSQL'), array('default' => array('php'))),
21
+			'float' => new EE_Float_Input(),
22
+			'essay' => new EE_Text_Area_Input(),
23
+			'amenities' => new EE_Select_Multiple_Input(
24
+				array(
25
+					'hottub' => 'Hot Tub',
26
+					'balcony' => "Balcony",
27
+					'skylight' => 'SkyLight',
28
+					'no_axe' => 'No Axe Murderers'
29
+				),
30
+				array(
31
+					'default' => array(
32
+						'hottub',
33
+						'no_axe' ),
34
+				)
35
+			),
36
+			'payment_methods' => new EE_Select_Multi_Model_Input(EEM_Payment_Method::instance()->get_all()),
37
+			);
38
+		$this->_layout_strategy = new EE_Div_Per_Section_Layout();
39
+		parent::__construct();
40
+	}
41 41
 
42
-    /**
43
-     * Extra validation for the 'name' input.
44
-     * @param EE_Text_Input $form_input
45
-     */
46
-    public function _validate_name($form_input)
47
-    {
48
-        if ($form_input->raw_value() != 'Mike') {
49
-            $form_input->add_validation_error(esc_html__("You are not mike. You must be brent or darren. Thats ok, I guess", 'event_espresso'), 'not-mike');
50
-        }
51
-    }
42
+	/**
43
+	 * Extra validation for the 'name' input.
44
+	 * @param EE_Text_Input $form_input
45
+	 */
46
+	public function _validate_name($form_input)
47
+	{
48
+		if ($form_input->raw_value() != 'Mike') {
49
+			$form_input->add_validation_error(esc_html__("You are not mike. You must be brent or darren. Thats ok, I guess", 'event_espresso'), 'not-mike');
50
+		}
51
+	}
52 52
 
53
-    public function _validate()
54
-    {
55
-        parent::_validate();
56
-        if (
57
-            $this->_subsections['shirt_size']->normalized_value() == 's'
58
-                && $this->_subsections['year_4']->normalized_value() < 2010
59
-        ) {
60
-            $this->add_validation_error(esc_html__("If you want a small shirt, you should be born after 2010. Otherwise theyre just too big", 'event_espresso'), 'too-old');
61
-        }
62
-    }
53
+	public function _validate()
54
+	{
55
+		parent::_validate();
56
+		if (
57
+			$this->_subsections['shirt_size']->normalized_value() == 's'
58
+				&& $this->_subsections['year_4']->normalized_value() < 2010
59
+		) {
60
+			$this->add_validation_error(esc_html__("If you want a small shirt, you should be born after 2010. Otherwise theyre just too big", 'event_espresso'), 'too-old');
61
+		}
62
+	}
63 63
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -6,9 +6,9 @@  discard block
 block discarded – undo
6 6
     {
7 7
         $this->_subsections = array(
8 8
             'h1' => new EE_Form_Section_HTML('hello wordl'),
9
-            'name' => new EE_Text_Input(array('required' => true,'default' => 'your name here')),
9
+            'name' => new EE_Text_Input(array('required' => true, 'default' => 'your name here')),
10 10
             'email' => new EE_Email_Input(array('required' => false)),
11
-            'shirt_size' => new EE_Select_Input(array('' => 'Please select...', 's' =>  esc_html__("Small", "event_espresso"),'m' =>  esc_html__("Medium", "event_espresso"),'l' =>  esc_html__("Large", "event_espresso")), array('required' => true,'default' => 's')),
11
+            'shirt_size' => new EE_Select_Input(array('' => 'Please select...', 's' =>  esc_html__("Small", "event_espresso"), 'm' =>  esc_html__("Medium", "event_espresso"), 'l' =>  esc_html__("Large", "event_espresso")), array('required' => true, 'default' => 's')),
12 12
             'month_normal' => new EE_Month_Input(),
13 13
             'month_leading_zero' => new EE_Month_Input(true),
14 14
             'year_2' => new EE_Year_Input(false, 1, 1),
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
             'credit_card' => new EE_Credit_Card_Input(),
18 18
             'image_1' => new EE_Admin_File_Uploader_Input(),
19 19
             'image_2' => new EE_Admin_File_Uploader_Input(),
20
-            'skillz' => new EE_Checkbox_Multi_Input(array('php' => 'PHP','mysql' => 'MYSQL'), array('default' => array('php'))),
20
+            'skillz' => new EE_Checkbox_Multi_Input(array('php' => 'PHP', 'mysql' => 'MYSQL'), array('default' => array('php'))),
21 21
             'float' => new EE_Float_Input(),
22 22
             'essay' => new EE_Text_Area_Input(),
23 23
             'amenities' => new EE_Select_Multiple_Input(
Please login to merge, or discard this patch.
form_sections/payment_methods/EE_Billing_Attendee_Info_Form.form.php 2 patches
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -14,172 +14,172 @@
 block discarded – undo
14 14
 class EE_Billing_Attendee_Info_Form extends EE_Billing_Info_Form
15 15
 {
16 16
 
17
-    /**
18
-     *
19
-     * @param EE_Payment_Method $payment_method
20
-     * @param array $options_array @see EE_Form_Section_Proper::__construct()
21
-     */
22
-    public function __construct(EE_Payment_Method $payment_method, $options_array = array())
23
-    {
24
-        $options_array['subsections'] = array_merge(
25
-            array(
26
-                'first_name'    => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-fname', 'html_label_text' => esc_html__('First Name', 'event_espresso') )),
27
-                'last_name'     => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-lname', 'html_label_text' => esc_html__('Last Name', 'event_espresso') )),
28
-                'email'             => new EE_Email_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-email', 'html_label_text' => esc_html__('Email', 'event_espresso') )),
29
-                'address'           => new EE_Text_Input(array( 'html_label_text' =>  esc_html__('Address', 'event_espresso'), 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-address' )),
30
-                'address2'      => new EE_Text_Input(array( 'html_label_text' => esc_html__('Address 2', 'event_espresso'), 'html_class' => 'ee-billing-qstn ee-billing-qstn-address2' )),
31
-                'city'                  => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-city', 'html_label_text' => esc_html__('City', 'event_espresso') )),
32
-                'state'                 => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__state_field', new EE_State_Select_Input(null, array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-state', 'html_label_text' => esc_html__('State', 'event_espresso') ))),
33
-                'country'           => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__country_field', new EE_Country_Select_Input(null, array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-country', 'html_label_text' => esc_html__('Country', 'event_espresso') ))),
34
-                'zip'                   => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-zip', 'html_label_text' => esc_html__('Zip', 'event_espresso') )),
35
-                'phone'         => new EE_Text_Input(array( 'html_class' => 'ee-billing-qstn ee-billing-qstn-phone', 'html_label_text' => esc_html__('Phone', 'event_espresso') )),
36
-            ),
37
-            isset($options_array['subsections']) ? $options_array['subsections'] : array()
38
-        );
17
+	/**
18
+	 *
19
+	 * @param EE_Payment_Method $payment_method
20
+	 * @param array $options_array @see EE_Form_Section_Proper::__construct()
21
+	 */
22
+	public function __construct(EE_Payment_Method $payment_method, $options_array = array())
23
+	{
24
+		$options_array['subsections'] = array_merge(
25
+			array(
26
+				'first_name'    => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-fname', 'html_label_text' => esc_html__('First Name', 'event_espresso') )),
27
+				'last_name'     => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-lname', 'html_label_text' => esc_html__('Last Name', 'event_espresso') )),
28
+				'email'             => new EE_Email_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-email', 'html_label_text' => esc_html__('Email', 'event_espresso') )),
29
+				'address'           => new EE_Text_Input(array( 'html_label_text' =>  esc_html__('Address', 'event_espresso'), 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-address' )),
30
+				'address2'      => new EE_Text_Input(array( 'html_label_text' => esc_html__('Address 2', 'event_espresso'), 'html_class' => 'ee-billing-qstn ee-billing-qstn-address2' )),
31
+				'city'                  => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-city', 'html_label_text' => esc_html__('City', 'event_espresso') )),
32
+				'state'                 => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__state_field', new EE_State_Select_Input(null, array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-state', 'html_label_text' => esc_html__('State', 'event_espresso') ))),
33
+				'country'           => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__country_field', new EE_Country_Select_Input(null, array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-country', 'html_label_text' => esc_html__('Country', 'event_espresso') ))),
34
+				'zip'                   => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-zip', 'html_label_text' => esc_html__('Zip', 'event_espresso') )),
35
+				'phone'         => new EE_Text_Input(array( 'html_class' => 'ee-billing-qstn ee-billing-qstn-phone', 'html_label_text' => esc_html__('Phone', 'event_espresso') )),
36
+			),
37
+			isset($options_array['subsections']) ? $options_array['subsections'] : array()
38
+		);
39 39
 
40
-        parent::__construct($payment_method, $options_array);
41
-    }
40
+		parent::__construct($payment_method, $options_array);
41
+	}
42 42
 
43
-    /**
44
-     * Sets the defaults for the billing form according to the attendee's details
45
-     * @param EE_Attendee $attendee
46
-     */
47
-    public function populate_from_attendee($attendee)
48
-    {
49
-        $attendee = EEM_Attendee::instance()->ensure_is_obj($attendee);
43
+	/**
44
+	 * Sets the defaults for the billing form according to the attendee's details
45
+	 * @param EE_Attendee $attendee
46
+	 */
47
+	public function populate_from_attendee($attendee)
48
+	{
49
+		$attendee = EEM_Attendee::instance()->ensure_is_obj($attendee);
50 50
 
51
-        /** @var $attendee EE_Attendee */
52
-        $this->populate_defaults(
53
-            apply_filters(
54
-                'FHEE__EE_Billing_Attendee_Info_Form__populate_from_attendee',
55
-                array(
56
-                    'first_name' => $attendee->fname(),
57
-                    'last_name' => $attendee->lname(),
58
-                    'email' => $attendee->email(),
59
-                    'address' => $attendee->address(),
60
-                    'address2' => $attendee->address2(),
61
-                    'city' => $attendee->city(),
62
-                    'state' => $this->getAttendeeStateValueForForm($attendee),
63
-                    'country' => $attendee->country_ID(),
64
-                    'zip' => $attendee->zip(),
65
-                    'phone' => $attendee->phone(),
66
-                ),
67
-                $attendee,
68
-                $this
69
-            )
70
-        );
71
-    }
51
+		/** @var $attendee EE_Attendee */
52
+		$this->populate_defaults(
53
+			apply_filters(
54
+				'FHEE__EE_Billing_Attendee_Info_Form__populate_from_attendee',
55
+				array(
56
+					'first_name' => $attendee->fname(),
57
+					'last_name' => $attendee->lname(),
58
+					'email' => $attendee->email(),
59
+					'address' => $attendee->address(),
60
+					'address2' => $attendee->address2(),
61
+					'city' => $attendee->city(),
62
+					'state' => $this->getAttendeeStateValueForForm($attendee),
63
+					'country' => $attendee->country_ID(),
64
+					'zip' => $attendee->zip(),
65
+					'phone' => $attendee->phone(),
66
+				),
67
+				$attendee,
68
+				$this
69
+			)
70
+		);
71
+	}
72 72
 
73
-    /**
74
-     * Gets the default value to use for the billing form's state value.
75
-     * @since 4.10.0.p
76
-     * @param EE_Attendee $attendee
77
-     * @return string
78
-     * @throws EE_Error2
79
-     */
80
-    protected function getAttendeeStateValueForForm(EE_Attendee $attendee)
81
-    {
82
-        // If the state input was removed, just return a blank string.
83
-        if (! $this->has_subsection('state')) {
84
-            return '';
85
-        }
86
-        $state_input =  $this->get_input('state', false);
87
-        if ($state_input instanceof EE_State_Select_Input) {
88
-            $state_field_to_use =  $state_input->valueFieldName();
89
-        } else {
90
-            $state_field_to_use = 'STA_ID';
91
-        }
92
-        switch ($state_field_to_use) {
93
-            case 'STA_abbrev':
94
-                $state_value = $attendee->state_abbrev();
95
-                break;
96
-            case 'STA_name':
97
-                $state_value = $attendee->state_name();
98
-                break;
99
-            default:
100
-                $state_value = $attendee->state_ID();
101
-        }
102
-        return $state_value;
103
-    }
73
+	/**
74
+	 * Gets the default value to use for the billing form's state value.
75
+	 * @since 4.10.0.p
76
+	 * @param EE_Attendee $attendee
77
+	 * @return string
78
+	 * @throws EE_Error2
79
+	 */
80
+	protected function getAttendeeStateValueForForm(EE_Attendee $attendee)
81
+	{
82
+		// If the state input was removed, just return a blank string.
83
+		if (! $this->has_subsection('state')) {
84
+			return '';
85
+		}
86
+		$state_input =  $this->get_input('state', false);
87
+		if ($state_input instanceof EE_State_Select_Input) {
88
+			$state_field_to_use =  $state_input->valueFieldName();
89
+		} else {
90
+			$state_field_to_use = 'STA_ID';
91
+		}
92
+		switch ($state_field_to_use) {
93
+			case 'STA_abbrev':
94
+				$state_value = $attendee->state_abbrev();
95
+				break;
96
+			case 'STA_name':
97
+				$state_value = $attendee->state_name();
98
+				break;
99
+			default:
100
+				$state_value = $attendee->state_ID();
101
+		}
102
+		return $state_value;
103
+	}
104 104
 
105 105
 
106 106
 
107
-    /**
108
-     * copy_billing_form_data_to_attendee
109
-     * copies info from the billing form to the attendee's details
110
-     * @param \EE_Attendee $attendee - the attendee object to copy details to
111
-     * @return \EE_Attendee
112
-     */
113
-    public function copy_billing_form_data_to_attendee(EE_Attendee $attendee)
114
-    {
115
-        // grab billing form data
116
-        $data = $this->valid_data();
117
-        // copy first_name
118
-        if (! empty($data['first_name'])) {
119
-            $attendee->set_fname($data['first_name']);
120
-        }
121
-        // copy last_name
122
-        if (! empty($data['last_name'])) {
123
-            $attendee->set_lname($data['last_name']);
124
-        }
125
-        // copy email
126
-        if (! empty($data['email'])) {
127
-            $attendee->set_email($data['email']);
128
-        }
129
-        // copy address
130
-        if (! empty($data['address'])) {
131
-            $attendee->set_address($data['address']);
132
-        }
133
-        // copy address2
134
-        if (! empty($data['address2'])) {
135
-            $attendee->set_address2($data['address2']);
136
-        }
137
-        // copy city
138
-        if (! empty($data['city'])) {
139
-            $attendee->set_city($data['city']);
140
-        }
141
-        // copy state
142
-        if (! empty($data['state'])) {
143
-            $attendee->set_state($data['state']);
144
-        }
145
-        // copy country
146
-        if (! empty($data['country'])) {
147
-            $attendee->set_country($data['country']);
148
-        }
149
-        // copy zip
150
-        if (! empty($data['zip'])) {
151
-            $attendee->set_zip($data['zip']);
152
-        }
153
-        // copy phone
154
-        if (! empty($data['phone'])) {
155
-            $attendee->set_phone($data['phone']);
156
-        }
157
-        return $attendee;
158
-    }
107
+	/**
108
+	 * copy_billing_form_data_to_attendee
109
+	 * copies info from the billing form to the attendee's details
110
+	 * @param \EE_Attendee $attendee - the attendee object to copy details to
111
+	 * @return \EE_Attendee
112
+	 */
113
+	public function copy_billing_form_data_to_attendee(EE_Attendee $attendee)
114
+	{
115
+		// grab billing form data
116
+		$data = $this->valid_data();
117
+		// copy first_name
118
+		if (! empty($data['first_name'])) {
119
+			$attendee->set_fname($data['first_name']);
120
+		}
121
+		// copy last_name
122
+		if (! empty($data['last_name'])) {
123
+			$attendee->set_lname($data['last_name']);
124
+		}
125
+		// copy email
126
+		if (! empty($data['email'])) {
127
+			$attendee->set_email($data['email']);
128
+		}
129
+		// copy address
130
+		if (! empty($data['address'])) {
131
+			$attendee->set_address($data['address']);
132
+		}
133
+		// copy address2
134
+		if (! empty($data['address2'])) {
135
+			$attendee->set_address2($data['address2']);
136
+		}
137
+		// copy city
138
+		if (! empty($data['city'])) {
139
+			$attendee->set_city($data['city']);
140
+		}
141
+		// copy state
142
+		if (! empty($data['state'])) {
143
+			$attendee->set_state($data['state']);
144
+		}
145
+		// copy country
146
+		if (! empty($data['country'])) {
147
+			$attendee->set_country($data['country']);
148
+		}
149
+		// copy zip
150
+		if (! empty($data['zip'])) {
151
+			$attendee->set_zip($data['zip']);
152
+		}
153
+		// copy phone
154
+		if (! empty($data['phone'])) {
155
+			$attendee->set_phone($data['phone']);
156
+		}
157
+		return $attendee;
158
+	}
159 159
 
160 160
 
161
-    /**
162
-     * create_attendee_from_billing_form_data
163
-     * uses info from the billing form to create a new attendee
164
-     * @return \EE_Attendee
165
-     */
166
-    public function create_attendee_from_billing_form_data()
167
-    {
168
-        // grab billing form data
169
-        $data = $this->valid_data();
170
-        return EE_Attendee::new_instance(array(
171
-            'ATT_fname'         => ! empty($data['first_name']) ? $data['first_name'] : '',
172
-            'ATT_lname'         => ! empty($data['last_name']) ? $data['last_name'] : '',
173
-            'ATT_email'         => ! empty($data['email']) ? $data['email'] : '',
174
-            'ATT_address'       => ! empty($data['address']) ? $data['address'] : '',
175
-            'ATT_address2'  => ! empty($data['address2']) ? $data['address2'] : '',
176
-            'ATT_city'          => ! empty($data['city']) ? $data['city'] : '',
177
-            'STA_ID'                => ! empty($data['state']) ? $data['state'] : '',
178
-            'CNT_ISO'           => ! empty($data['country']) ? $data['country'] : '',
179
-            'ATT_zip'               => ! empty($data['zip']) ? $data['zip'] : '',
180
-            'ATT_phone'         => ! empty($data['phone']) ? $data['phone'] : '',
181
-        ));
182
-    }
161
+	/**
162
+	 * create_attendee_from_billing_form_data
163
+	 * uses info from the billing form to create a new attendee
164
+	 * @return \EE_Attendee
165
+	 */
166
+	public function create_attendee_from_billing_form_data()
167
+	{
168
+		// grab billing form data
169
+		$data = $this->valid_data();
170
+		return EE_Attendee::new_instance(array(
171
+			'ATT_fname'         => ! empty($data['first_name']) ? $data['first_name'] : '',
172
+			'ATT_lname'         => ! empty($data['last_name']) ? $data['last_name'] : '',
173
+			'ATT_email'         => ! empty($data['email']) ? $data['email'] : '',
174
+			'ATT_address'       => ! empty($data['address']) ? $data['address'] : '',
175
+			'ATT_address2'  => ! empty($data['address2']) ? $data['address2'] : '',
176
+			'ATT_city'          => ! empty($data['city']) ? $data['city'] : '',
177
+			'STA_ID'                => ! empty($data['state']) ? $data['state'] : '',
178
+			'CNT_ISO'           => ! empty($data['country']) ? $data['country'] : '',
179
+			'ATT_zip'               => ! empty($data['zip']) ? $data['zip'] : '',
180
+			'ATT_phone'         => ! empty($data['phone']) ? $data['phone'] : '',
181
+		));
182
+	}
183 183
 }
184 184
 
185 185
 // End of file EE_Billing_Attendee_Info_Form.form.php
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -23,16 +23,16 @@  discard block
 block discarded – undo
23 23
     {
24 24
         $options_array['subsections'] = array_merge(
25 25
             array(
26
-                'first_name'    => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-fname', 'html_label_text' => esc_html__('First Name', 'event_espresso') )),
27
-                'last_name'     => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-lname', 'html_label_text' => esc_html__('Last Name', 'event_espresso') )),
28
-                'email'             => new EE_Email_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-email', 'html_label_text' => esc_html__('Email', 'event_espresso') )),
29
-                'address'           => new EE_Text_Input(array( 'html_label_text' =>  esc_html__('Address', 'event_espresso'), 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-address' )),
30
-                'address2'      => new EE_Text_Input(array( 'html_label_text' => esc_html__('Address 2', 'event_espresso'), 'html_class' => 'ee-billing-qstn ee-billing-qstn-address2' )),
31
-                'city'                  => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-city', 'html_label_text' => esc_html__('City', 'event_espresso') )),
32
-                'state'                 => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__state_field', new EE_State_Select_Input(null, array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-state', 'html_label_text' => esc_html__('State', 'event_espresso') ))),
33
-                'country'           => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__country_field', new EE_Country_Select_Input(null, array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-country', 'html_label_text' => esc_html__('Country', 'event_espresso') ))),
34
-                'zip'                   => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-zip', 'html_label_text' => esc_html__('Zip', 'event_espresso') )),
35
-                'phone'         => new EE_Text_Input(array( 'html_class' => 'ee-billing-qstn ee-billing-qstn-phone', 'html_label_text' => esc_html__('Phone', 'event_espresso') )),
26
+                'first_name'    => new EE_Text_Input(array('required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-fname', 'html_label_text' => esc_html__('First Name', 'event_espresso'))),
27
+                'last_name'     => new EE_Text_Input(array('required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-lname', 'html_label_text' => esc_html__('Last Name', 'event_espresso'))),
28
+                'email'             => new EE_Email_Input(array('required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-email', 'html_label_text' => esc_html__('Email', 'event_espresso'))),
29
+                'address'           => new EE_Text_Input(array('html_label_text' =>  esc_html__('Address', 'event_espresso'), 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-address')),
30
+                'address2'      => new EE_Text_Input(array('html_label_text' => esc_html__('Address 2', 'event_espresso'), 'html_class' => 'ee-billing-qstn ee-billing-qstn-address2')),
31
+                'city'                  => new EE_Text_Input(array('required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-city', 'html_label_text' => esc_html__('City', 'event_espresso'))),
32
+                'state'                 => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__state_field', new EE_State_Select_Input(null, array('required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-state', 'html_label_text' => esc_html__('State', 'event_espresso')))),
33
+                'country'           => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__country_field', new EE_Country_Select_Input(null, array('required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-country', 'html_label_text' => esc_html__('Country', 'event_espresso')))),
34
+                'zip'                   => new EE_Text_Input(array('required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-zip', 'html_label_text' => esc_html__('Zip', 'event_espresso'))),
35
+                'phone'         => new EE_Text_Input(array('html_class' => 'ee-billing-qstn ee-billing-qstn-phone', 'html_label_text' => esc_html__('Phone', 'event_espresso'))),
36 36
             ),
37 37
             isset($options_array['subsections']) ? $options_array['subsections'] : array()
38 38
         );
@@ -80,12 +80,12 @@  discard block
 block discarded – undo
80 80
     protected function getAttendeeStateValueForForm(EE_Attendee $attendee)
81 81
     {
82 82
         // If the state input was removed, just return a blank string.
83
-        if (! $this->has_subsection('state')) {
83
+        if ( ! $this->has_subsection('state')) {
84 84
             return '';
85 85
         }
86
-        $state_input =  $this->get_input('state', false);
86
+        $state_input = $this->get_input('state', false);
87 87
         if ($state_input instanceof EE_State_Select_Input) {
88
-            $state_field_to_use =  $state_input->valueFieldName();
88
+            $state_field_to_use = $state_input->valueFieldName();
89 89
         } else {
90 90
             $state_field_to_use = 'STA_ID';
91 91
         }
@@ -115,43 +115,43 @@  discard block
 block discarded – undo
115 115
         // grab billing form data
116 116
         $data = $this->valid_data();
117 117
         // copy first_name
118
-        if (! empty($data['first_name'])) {
118
+        if ( ! empty($data['first_name'])) {
119 119
             $attendee->set_fname($data['first_name']);
120 120
         }
121 121
         // copy last_name
122
-        if (! empty($data['last_name'])) {
122
+        if ( ! empty($data['last_name'])) {
123 123
             $attendee->set_lname($data['last_name']);
124 124
         }
125 125
         // copy email
126
-        if (! empty($data['email'])) {
126
+        if ( ! empty($data['email'])) {
127 127
             $attendee->set_email($data['email']);
128 128
         }
129 129
         // copy address
130
-        if (! empty($data['address'])) {
130
+        if ( ! empty($data['address'])) {
131 131
             $attendee->set_address($data['address']);
132 132
         }
133 133
         // copy address2
134
-        if (! empty($data['address2'])) {
134
+        if ( ! empty($data['address2'])) {
135 135
             $attendee->set_address2($data['address2']);
136 136
         }
137 137
         // copy city
138
-        if (! empty($data['city'])) {
138
+        if ( ! empty($data['city'])) {
139 139
             $attendee->set_city($data['city']);
140 140
         }
141 141
         // copy state
142
-        if (! empty($data['state'])) {
142
+        if ( ! empty($data['state'])) {
143 143
             $attendee->set_state($data['state']);
144 144
         }
145 145
         // copy country
146
-        if (! empty($data['country'])) {
146
+        if ( ! empty($data['country'])) {
147 147
             $attendee->set_country($data['country']);
148 148
         }
149 149
         // copy zip
150
-        if (! empty($data['zip'])) {
150
+        if ( ! empty($data['zip'])) {
151 151
             $attendee->set_zip($data['zip']);
152 152
         }
153 153
         // copy phone
154
-        if (! empty($data['phone'])) {
154
+        if ( ! empty($data['phone'])) {
155 155
             $attendee->set_phone($data['phone']);
156 156
         }
157 157
         return $attendee;
Please login to merge, or discard this patch.
libraries/form_sections/payment_methods/EE_Payment_Method_Form.form.php 2 patches
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -7,195 +7,195 @@
 block discarded – undo
7 7
 class EE_Payment_Method_Form extends EE_Model_Form_Section
8 8
 {
9 9
 
10
-    /**
11
-     * All the subsection inputs that correspond ot extra meta rows
12
-     * for this payment method
13
-     *
14
-     * @var EE_Form_Input_Base[]
15
-     */
16
-    protected $_extra_meta_inputs = array();
17
-
18
-    /**
19
-     * Because payment method form might DELAY part of construction, we want to remember
20
-     * what options were passed in
21
-     *
22
-     * @var array
23
-     */
24
-    protected $_options_array = array();
25
-
26
-    /**
27
-     * The payment method type for this form
28
-     *
29
-     * @var EE_PMT_Base
30
-     */
31
-    protected $_payment_method_type;
32
-
33
-
34
-
35
-    /**
36
-     * @param array      $options_array       {
37
-     * @type string      $extra_meta_inputs   should be EE_Form_Section_Validatable[] which
38
-     *                                        will be _subsections and will be saved as extra meta on the payment
39
-     *                                        method object;
40
-     * @type EE_PMT_Base $payment_method_type the payment method type this form is for
41
-     * @see EE_Model_Form_Section::__construct() for more
42
-     *                                        }
43
-     */
44
-    public function __construct($options_array = array())
45
-    {
46
-        $this->_model = EEM_Payment_Method::instance();
47
-        $this->_options_array = $options_array;
48
-        if (isset($options_array['payment_method_type'])) {
49
-            $this->_payment_method_type = $options_array['payment_method_type'];
50
-        }
51
-        $options_array = $this->_options_array;
52
-        if (isset($options_array['extra_meta_inputs'])) {
53
-            $this->_extra_meta_inputs = array_merge($this->_extra_meta_inputs, $options_array['extra_meta_inputs']);
54
-        }
55
-        if ($this->_extra_meta_inputs) {
56
-            $this->_subsections = array_merge($this->_subsections, $this->_extra_meta_inputs);
57
-        }
58
-        $this->_subsections['PMD_button_url'] = new EE_Admin_File_Uploader_Input(
59
-            array('html_label_text' => esc_html__('Button URL', 'event_espresso'))
60
-        );
61
-        $this->_subsections['PMD_scope'] = new EE_Checkbox_Multi_Input(
62
-            EEM_Payment_Method::instance()->scopes(),
63
-            array(
64
-                'html_label_text' => $this->_model->field_settings_for('PMD_scope')->get_nicename()
65
-                                     . EEH_Template::get_help_tab_link('payment_methods_overview'),
66
-            )
67
-        );
68
-        // setup the currency options
69
-        $this->_subsections['Currency'] = new EE_Select_Multi_Model_Input(
70
-            EEM_Currency::instance()->get_all_currencies_usable_by($this->_payment_method_type),
71
-            array(
72
-                'html_label_text' => esc_html__('Currencies Supported', 'event_espresso'),
73
-                'required'        => true,
74
-            )
75
-        );
76
-        $this->_subsections['PMD_order'] = new EE_Text_Input(array(
77
-            'html_label_text'        => esc_html__('Order', 'event_espresso'),
78
-            'html_help_text'         => esc_html__('Lowest numbers will be shown first', 'event_espresso'),
79
-            'normalization_strategy' => new EE_Int_Normalization(),
80
-            'validation_strategies'  => array(
81
-                new EE_Int_Validation_Strategy(),
82
-            ),
83
-            'default'                => 0,
84
-        ));
85
-        $this->_layout_strategy = new EE_Admin_Two_Column_Layout();
86
-        parent::__construct($options_array);
87
-        $debug_mode = isset($this->_subsections['PMD_debug_mode']) ? $this->_subsections['PMD_debug_mode'] : null;
88
-        if ($debug_mode instanceof EE_Form_Input_Base) {
89
-            $debug_mode->set_html_help_text(esc_html__(
90
-                'This payment method has a Sandbox Server (also known as Testing Server, Development Server, Quality Assurance Server, etc). While in debug mode and using this sandbox server, real payments will not be processed.',
91
-                'event_espresso'
92
-            ));
93
-        }
94
-    }
95
-
96
-
97
-
98
-    /**
99
-     * Finishes construction given the parent form section and this form section's name
100
-     *
101
-     * @param EE_Form_Section_Proper $parent_form_section
102
-     * @param string                 $name
103
-     * @throws EE_Error
104
-     */
105
-    public function _construct_finalize($parent_form_section, $name)
106
-    {
107
-        if (! $this->_payment_method_type instanceof EE_PMT_Base) {
108
-            throw new EE_Error(sprintf(esc_html__(
109
-                'Payment Method forms must have set their payment method type BEFORE calling _construct_finalize',
110
-                'event_espresso'
111
-            )));
112
-        }
113
-        // set the name of this form based on the payment method type
114
-        if (! $this->_name && ! $name) {
115
-            $name = str_replace(" ", "_", ucwords(str_replace("_", " ", ($this->_payment_method_type->system_name()))))
116
-                    . "_Settings_Form";
117
-        }
118
-        parent::_construct_finalize($parent_form_section, $name);
119
-    }
120
-
121
-
122
-
123
-    /**
124
-     * @param $payment_method_type
125
-     * @throws EE_Error
126
-     */
127
-    public function set_payment_method_type($payment_method_type)
128
-    {
129
-        if (! $payment_method_type instanceof EE_PMT_Base) {
130
-            throw new EE_Error(sprintf(esc_html__(
131
-                "Payment Method forms MUST set a payment method type by using _set_payment_method_type",
132
-                "event_espresso"
133
-            )));
134
-        }
135
-        $this->_payment_method_type = $payment_method_type;
136
-    }
137
-
138
-
139
-
140
-    /**
141
-     * extends the model form section's save method to also save the extra meta field values
142
-     *
143
-     * @return int ID of the payment method inserted, or true on update
144
-     */
145
-    public function save()
146
-    {
147
-        $parent_save_val = parent::save();
148
-        if ($this->_model_object && $this->_model_object->ID()) {
149
-            foreach ($this->_extra_meta_inputs as $input_name => $input) {
150
-                $this->_model_object->update_extra_meta($input_name, $input->normalized_value());
151
-            }
152
-        }
153
-        return $parent_save_val;
154
-    }
155
-
156
-
157
-
158
-    /**
159
-     * Overrides parent's populate_model_obj to also populate the extra meta fields
160
-     *
161
-     * @param EE_Base_Class $model_obj
162
-     */
163
-    public function populate_model_obj($model_obj)
164
-    {
165
-        $model_obj = $this->_model->ensure_is_obj($model_obj);
166
-        parent::populate_model_obj($model_obj);
167
-        $extra_meta = $model_obj->all_extra_meta_array();
168
-        foreach ($this->_extra_meta_inputs as $input_name => $extra_meta_input) {
169
-            if (isset($extra_meta[ $input_name ])) {
170
-                $extra_meta_input->set_default($extra_meta[ $input_name ]);
171
-            }
172
-        }
173
-    }
174
-
175
-
176
-
177
-    /**
178
-     * gets the default name of this form section if none is specified
179
-     *
180
-     * @return string
181
-     */
182
-    protected function _set_default_name_if_empty()
183
-    {
184
-        if (! $this->_name) {
185
-            $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form";
186
-            $this->_name = $default_name;
187
-        }
188
-    }
189
-
190
-
191
-
192
-    /**
193
-     * Gets all the extra meta inputs in this form
194
-     *
195
-     * @return EE_Form_Input_Base[]
196
-     */
197
-    public function extra_meta_inputs()
198
-    {
199
-        return $this->_extra_meta_inputs;
200
-    }
10
+	/**
11
+	 * All the subsection inputs that correspond ot extra meta rows
12
+	 * for this payment method
13
+	 *
14
+	 * @var EE_Form_Input_Base[]
15
+	 */
16
+	protected $_extra_meta_inputs = array();
17
+
18
+	/**
19
+	 * Because payment method form might DELAY part of construction, we want to remember
20
+	 * what options were passed in
21
+	 *
22
+	 * @var array
23
+	 */
24
+	protected $_options_array = array();
25
+
26
+	/**
27
+	 * The payment method type for this form
28
+	 *
29
+	 * @var EE_PMT_Base
30
+	 */
31
+	protected $_payment_method_type;
32
+
33
+
34
+
35
+	/**
36
+	 * @param array      $options_array       {
37
+	 * @type string      $extra_meta_inputs   should be EE_Form_Section_Validatable[] which
38
+	 *                                        will be _subsections and will be saved as extra meta on the payment
39
+	 *                                        method object;
40
+	 * @type EE_PMT_Base $payment_method_type the payment method type this form is for
41
+	 * @see EE_Model_Form_Section::__construct() for more
42
+	 *                                        }
43
+	 */
44
+	public function __construct($options_array = array())
45
+	{
46
+		$this->_model = EEM_Payment_Method::instance();
47
+		$this->_options_array = $options_array;
48
+		if (isset($options_array['payment_method_type'])) {
49
+			$this->_payment_method_type = $options_array['payment_method_type'];
50
+		}
51
+		$options_array = $this->_options_array;
52
+		if (isset($options_array['extra_meta_inputs'])) {
53
+			$this->_extra_meta_inputs = array_merge($this->_extra_meta_inputs, $options_array['extra_meta_inputs']);
54
+		}
55
+		if ($this->_extra_meta_inputs) {
56
+			$this->_subsections = array_merge($this->_subsections, $this->_extra_meta_inputs);
57
+		}
58
+		$this->_subsections['PMD_button_url'] = new EE_Admin_File_Uploader_Input(
59
+			array('html_label_text' => esc_html__('Button URL', 'event_espresso'))
60
+		);
61
+		$this->_subsections['PMD_scope'] = new EE_Checkbox_Multi_Input(
62
+			EEM_Payment_Method::instance()->scopes(),
63
+			array(
64
+				'html_label_text' => $this->_model->field_settings_for('PMD_scope')->get_nicename()
65
+									 . EEH_Template::get_help_tab_link('payment_methods_overview'),
66
+			)
67
+		);
68
+		// setup the currency options
69
+		$this->_subsections['Currency'] = new EE_Select_Multi_Model_Input(
70
+			EEM_Currency::instance()->get_all_currencies_usable_by($this->_payment_method_type),
71
+			array(
72
+				'html_label_text' => esc_html__('Currencies Supported', 'event_espresso'),
73
+				'required'        => true,
74
+			)
75
+		);
76
+		$this->_subsections['PMD_order'] = new EE_Text_Input(array(
77
+			'html_label_text'        => esc_html__('Order', 'event_espresso'),
78
+			'html_help_text'         => esc_html__('Lowest numbers will be shown first', 'event_espresso'),
79
+			'normalization_strategy' => new EE_Int_Normalization(),
80
+			'validation_strategies'  => array(
81
+				new EE_Int_Validation_Strategy(),
82
+			),
83
+			'default'                => 0,
84
+		));
85
+		$this->_layout_strategy = new EE_Admin_Two_Column_Layout();
86
+		parent::__construct($options_array);
87
+		$debug_mode = isset($this->_subsections['PMD_debug_mode']) ? $this->_subsections['PMD_debug_mode'] : null;
88
+		if ($debug_mode instanceof EE_Form_Input_Base) {
89
+			$debug_mode->set_html_help_text(esc_html__(
90
+				'This payment method has a Sandbox Server (also known as Testing Server, Development Server, Quality Assurance Server, etc). While in debug mode and using this sandbox server, real payments will not be processed.',
91
+				'event_espresso'
92
+			));
93
+		}
94
+	}
95
+
96
+
97
+
98
+	/**
99
+	 * Finishes construction given the parent form section and this form section's name
100
+	 *
101
+	 * @param EE_Form_Section_Proper $parent_form_section
102
+	 * @param string                 $name
103
+	 * @throws EE_Error
104
+	 */
105
+	public function _construct_finalize($parent_form_section, $name)
106
+	{
107
+		if (! $this->_payment_method_type instanceof EE_PMT_Base) {
108
+			throw new EE_Error(sprintf(esc_html__(
109
+				'Payment Method forms must have set their payment method type BEFORE calling _construct_finalize',
110
+				'event_espresso'
111
+			)));
112
+		}
113
+		// set the name of this form based on the payment method type
114
+		if (! $this->_name && ! $name) {
115
+			$name = str_replace(" ", "_", ucwords(str_replace("_", " ", ($this->_payment_method_type->system_name()))))
116
+					. "_Settings_Form";
117
+		}
118
+		parent::_construct_finalize($parent_form_section, $name);
119
+	}
120
+
121
+
122
+
123
+	/**
124
+	 * @param $payment_method_type
125
+	 * @throws EE_Error
126
+	 */
127
+	public function set_payment_method_type($payment_method_type)
128
+	{
129
+		if (! $payment_method_type instanceof EE_PMT_Base) {
130
+			throw new EE_Error(sprintf(esc_html__(
131
+				"Payment Method forms MUST set a payment method type by using _set_payment_method_type",
132
+				"event_espresso"
133
+			)));
134
+		}
135
+		$this->_payment_method_type = $payment_method_type;
136
+	}
137
+
138
+
139
+
140
+	/**
141
+	 * extends the model form section's save method to also save the extra meta field values
142
+	 *
143
+	 * @return int ID of the payment method inserted, or true on update
144
+	 */
145
+	public function save()
146
+	{
147
+		$parent_save_val = parent::save();
148
+		if ($this->_model_object && $this->_model_object->ID()) {
149
+			foreach ($this->_extra_meta_inputs as $input_name => $input) {
150
+				$this->_model_object->update_extra_meta($input_name, $input->normalized_value());
151
+			}
152
+		}
153
+		return $parent_save_val;
154
+	}
155
+
156
+
157
+
158
+	/**
159
+	 * Overrides parent's populate_model_obj to also populate the extra meta fields
160
+	 *
161
+	 * @param EE_Base_Class $model_obj
162
+	 */
163
+	public function populate_model_obj($model_obj)
164
+	{
165
+		$model_obj = $this->_model->ensure_is_obj($model_obj);
166
+		parent::populate_model_obj($model_obj);
167
+		$extra_meta = $model_obj->all_extra_meta_array();
168
+		foreach ($this->_extra_meta_inputs as $input_name => $extra_meta_input) {
169
+			if (isset($extra_meta[ $input_name ])) {
170
+				$extra_meta_input->set_default($extra_meta[ $input_name ]);
171
+			}
172
+		}
173
+	}
174
+
175
+
176
+
177
+	/**
178
+	 * gets the default name of this form section if none is specified
179
+	 *
180
+	 * @return string
181
+	 */
182
+	protected function _set_default_name_if_empty()
183
+	{
184
+		if (! $this->_name) {
185
+			$default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form";
186
+			$this->_name = $default_name;
187
+		}
188
+	}
189
+
190
+
191
+
192
+	/**
193
+	 * Gets all the extra meta inputs in this form
194
+	 *
195
+	 * @return EE_Form_Input_Base[]
196
+	 */
197
+	public function extra_meta_inputs()
198
+	{
199
+		return $this->_extra_meta_inputs;
200
+	}
201 201
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -104,14 +104,14 @@  discard block
 block discarded – undo
104 104
      */
105 105
     public function _construct_finalize($parent_form_section, $name)
106 106
     {
107
-        if (! $this->_payment_method_type instanceof EE_PMT_Base) {
107
+        if ( ! $this->_payment_method_type instanceof EE_PMT_Base) {
108 108
             throw new EE_Error(sprintf(esc_html__(
109 109
                 'Payment Method forms must have set their payment method type BEFORE calling _construct_finalize',
110 110
                 'event_espresso'
111 111
             )));
112 112
         }
113 113
         // set the name of this form based on the payment method type
114
-        if (! $this->_name && ! $name) {
114
+        if ( ! $this->_name && ! $name) {
115 115
             $name = str_replace(" ", "_", ucwords(str_replace("_", " ", ($this->_payment_method_type->system_name()))))
116 116
                     . "_Settings_Form";
117 117
         }
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
      */
127 127
     public function set_payment_method_type($payment_method_type)
128 128
     {
129
-        if (! $payment_method_type instanceof EE_PMT_Base) {
129
+        if ( ! $payment_method_type instanceof EE_PMT_Base) {
130 130
             throw new EE_Error(sprintf(esc_html__(
131 131
                 "Payment Method forms MUST set a payment method type by using _set_payment_method_type",
132 132
                 "event_espresso"
@@ -166,8 +166,8 @@  discard block
 block discarded – undo
166 166
         parent::populate_model_obj($model_obj);
167 167
         $extra_meta = $model_obj->all_extra_meta_array();
168 168
         foreach ($this->_extra_meta_inputs as $input_name => $extra_meta_input) {
169
-            if (isset($extra_meta[ $input_name ])) {
170
-                $extra_meta_input->set_default($extra_meta[ $input_name ]);
169
+            if (isset($extra_meta[$input_name])) {
170
+                $extra_meta_input->set_default($extra_meta[$input_name]);
171 171
             }
172 172
         }
173 173
     }
@@ -181,8 +181,8 @@  discard block
 block discarded – undo
181 181
      */
182 182
     protected function _set_default_name_if_empty()
183 183
     {
184
-        if (! $this->_name) {
185
-            $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form";
184
+        if ( ! $this->_name) {
185
+            $default_name = str_replace("EEM_", "", get_class($this->_model))."_Model_Form";
186 186
             $this->_name = $default_name;
187 187
         }
188 188
     }
Please login to merge, or discard this patch.
strategies/display/EE_Admin_File_Uploader_Display_Strategy.strategy.php 2 patches
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -12,73 +12,73 @@
 block discarded – undo
12 12
 class EE_Admin_File_Uploader_Display_Strategy extends EE_Display_Strategy_Base
13 13
 {
14 14
 
15
-    /**
16
-     * Its important this media only get enqueued AFTER init, but before the footer... where the
17
-     * rest of our forms JS gets enqueued. Otherwise the JS gets enqueued fine, and loaded on the page fine,
18
-     * but when you upload an image it gets uploaded fine to the server, but it doesn't display and reports an error
19
-     * (also it doesn't show any of the currently existing media in the modal window that pops up when you click the button
20
-     * to select media).
21
-     * Besides that, no special consideration should be required to make the media uploader appear, besides having
22
-     * this input displayed.
23
-     * @deprecated. enqueue_js should be called automatically now
24
-     */
25
-    public static function enqueue_scripts()
26
-    {
27
-        EE_Error::doing_it_wrong(__FUNCTION__, esc_html__('EE_Admin_File_Uploader_Display_Strategy::enqueue_scripts() no longer needs to be called in order to display the admin uploader input correctly. This is handled now by EE_Admin_File_Uploader_Display_Strategy::enqueue_js() which is called automatically when enqueueing JS and CSS for the form', 'event_espresso'), '4.9.8.rc.015');
28
-        wp_enqueue_media();
29
-        wp_enqueue_script('media-upload');
30
-        wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL . 'scripts/ee-media-uploader.js');
31
-    }
15
+	/**
16
+	 * Its important this media only get enqueued AFTER init, but before the footer... where the
17
+	 * rest of our forms JS gets enqueued. Otherwise the JS gets enqueued fine, and loaded on the page fine,
18
+	 * but when you upload an image it gets uploaded fine to the server, but it doesn't display and reports an error
19
+	 * (also it doesn't show any of the currently existing media in the modal window that pops up when you click the button
20
+	 * to select media).
21
+	 * Besides that, no special consideration should be required to make the media uploader appear, besides having
22
+	 * this input displayed.
23
+	 * @deprecated. enqueue_js should be called automatically now
24
+	 */
25
+	public static function enqueue_scripts()
26
+	{
27
+		EE_Error::doing_it_wrong(__FUNCTION__, esc_html__('EE_Admin_File_Uploader_Display_Strategy::enqueue_scripts() no longer needs to be called in order to display the admin uploader input correctly. This is handled now by EE_Admin_File_Uploader_Display_Strategy::enqueue_js() which is called automatically when enqueueing JS and CSS for the form', 'event_espresso'), '4.9.8.rc.015');
28
+		wp_enqueue_media();
29
+		wp_enqueue_script('media-upload');
30
+		wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL . 'scripts/ee-media-uploader.js');
31
+	}
32 32
 
33
-    /**
34
-     * Enqueues the JS and CSS needed to display this input
35
-     */
36
-    public function enqueue_js()
37
-    {
38
-        wp_enqueue_media();
39
-        wp_enqueue_script('media-upload');
40
-        wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL . 'scripts/ee-media-uploader.js');
41
-        parent::enqueue_js();
42
-    }
33
+	/**
34
+	 * Enqueues the JS and CSS needed to display this input
35
+	 */
36
+	public function enqueue_js()
37
+	{
38
+		wp_enqueue_media();
39
+		wp_enqueue_script('media-upload');
40
+		wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL . 'scripts/ee-media-uploader.js');
41
+		parent::enqueue_js();
42
+	}
43 43
 
44 44
 
45 45
 
46
-    /**
47
-     *
48
-     * @return string of html to display the field
49
-     */
46
+	/**
47
+	 *
48
+	 * @return string of html to display the field
49
+	 */
50 50
 
51
-    public function display()
52
-    {
53
-        // the actual input
54
-        $input = '<input type="text" size="34" ';
55
-        $input .= 'name="' . $this->_input->html_name() . '" ';
56
-        $input .= $this->_input->html_class() != '' ? 'class="large-text ee_media_url ' . $this->_input->html_class() . '" ' : 'class="large-text ee_media_url" ';
57
-        $input .= 'value="' . $this->_input->raw_value_in_form() . '" ';
58
-        $input .= $this->_input->other_html_attributes() . '>';
59
-        // image uploader
60
-        $uploader = EEH_HTML::link('#', '<img src="' . admin_url('images/media-button-image.gif') . '" >', esc_html__('click to add an image', 'event_espresso'), '', 'ee_media_upload');
61
-        // only attempt to show the image if it at least exists
62
-        $image = $this->src_exists($this->_input->raw_value()) ? EEH_HTML::br(2) . EEH_HTML::img($this->_input->raw_value(), esc_html__('logo', 'event_espresso'), '', 'ee_media_image') : '';
63
-        // html string
64
-        return EEH_HTML::div($input . EEH_HTML::nbsp() . $uploader . $image, '', 'ee_media_uploader_area');
65
-    }
51
+	public function display()
52
+	{
53
+		// the actual input
54
+		$input = '<input type="text" size="34" ';
55
+		$input .= 'name="' . $this->_input->html_name() . '" ';
56
+		$input .= $this->_input->html_class() != '' ? 'class="large-text ee_media_url ' . $this->_input->html_class() . '" ' : 'class="large-text ee_media_url" ';
57
+		$input .= 'value="' . $this->_input->raw_value_in_form() . '" ';
58
+		$input .= $this->_input->other_html_attributes() . '>';
59
+		// image uploader
60
+		$uploader = EEH_HTML::link('#', '<img src="' . admin_url('images/media-button-image.gif') . '" >', esc_html__('click to add an image', 'event_espresso'), '', 'ee_media_upload');
61
+		// only attempt to show the image if it at least exists
62
+		$image = $this->src_exists($this->_input->raw_value()) ? EEH_HTML::br(2) . EEH_HTML::img($this->_input->raw_value(), esc_html__('logo', 'event_espresso'), '', 'ee_media_image') : '';
63
+		// html string
64
+		return EEH_HTML::div($input . EEH_HTML::nbsp() . $uploader . $image, '', 'ee_media_uploader_area');
65
+	}
66 66
 
67 67
 
68 68
 
69
-    /**
70
-     * Asserts an image actually exists as quickly as possible by sending a HEAD
71
-     * request
72
-     * @param string $src
73
-     * @return boolean
74
-     */
75
-    protected function src_exists($src)
76
-    {
77
-        $results = wp_remote_head($src);
78
-        if (is_array($results) && ! $results instanceof WP_Error) {
79
-            return strpos($results['headers']['content-type'], "image") !== false;
80
-        } else {
81
-            return false;
82
-        }
83
-    }
69
+	/**
70
+	 * Asserts an image actually exists as quickly as possible by sending a HEAD
71
+	 * request
72
+	 * @param string $src
73
+	 * @return boolean
74
+	 */
75
+	protected function src_exists($src)
76
+	{
77
+		$results = wp_remote_head($src);
78
+		if (is_array($results) && ! $results instanceof WP_Error) {
79
+			return strpos($results['headers']['content-type'], "image") !== false;
80
+		} else {
81
+			return false;
82
+		}
83
+	}
84 84
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
         EE_Error::doing_it_wrong(__FUNCTION__, esc_html__('EE_Admin_File_Uploader_Display_Strategy::enqueue_scripts() no longer needs to be called in order to display the admin uploader input correctly. This is handled now by EE_Admin_File_Uploader_Display_Strategy::enqueue_js() which is called automatically when enqueueing JS and CSS for the form', 'event_espresso'), '4.9.8.rc.015');
28 28
         wp_enqueue_media();
29 29
         wp_enqueue_script('media-upload');
30
-        wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL . 'scripts/ee-media-uploader.js');
30
+        wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL.'scripts/ee-media-uploader.js');
31 31
     }
32 32
 
33 33
     /**
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
     {
38 38
         wp_enqueue_media();
39 39
         wp_enqueue_script('media-upload');
40
-        wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL . 'scripts/ee-media-uploader.js');
40
+        wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL.'scripts/ee-media-uploader.js');
41 41
         parent::enqueue_js();
42 42
     }
43 43
 
@@ -52,16 +52,16 @@  discard block
 block discarded – undo
52 52
     {
53 53
         // the actual input
54 54
         $input = '<input type="text" size="34" ';
55
-        $input .= 'name="' . $this->_input->html_name() . '" ';
56
-        $input .= $this->_input->html_class() != '' ? 'class="large-text ee_media_url ' . $this->_input->html_class() . '" ' : 'class="large-text ee_media_url" ';
57
-        $input .= 'value="' . $this->_input->raw_value_in_form() . '" ';
58
-        $input .= $this->_input->other_html_attributes() . '>';
55
+        $input .= 'name="'.$this->_input->html_name().'" ';
56
+        $input .= $this->_input->html_class() != '' ? 'class="large-text ee_media_url '.$this->_input->html_class().'" ' : 'class="large-text ee_media_url" ';
57
+        $input .= 'value="'.$this->_input->raw_value_in_form().'" ';
58
+        $input .= $this->_input->other_html_attributes().'>';
59 59
         // image uploader
60
-        $uploader = EEH_HTML::link('#', '<img src="' . admin_url('images/media-button-image.gif') . '" >', esc_html__('click to add an image', 'event_espresso'), '', 'ee_media_upload');
60
+        $uploader = EEH_HTML::link('#', '<img src="'.admin_url('images/media-button-image.gif').'" >', esc_html__('click to add an image', 'event_espresso'), '', 'ee_media_upload');
61 61
         // only attempt to show the image if it at least exists
62
-        $image = $this->src_exists($this->_input->raw_value()) ? EEH_HTML::br(2) . EEH_HTML::img($this->_input->raw_value(), esc_html__('logo', 'event_espresso'), '', 'ee_media_image') : '';
62
+        $image = $this->src_exists($this->_input->raw_value()) ? EEH_HTML::br(2).EEH_HTML::img($this->_input->raw_value(), esc_html__('logo', 'event_espresso'), '', 'ee_media_image') : '';
63 63
         // html string
64
-        return EEH_HTML::div($input . EEH_HTML::nbsp() . $uploader . $image, '', 'ee_media_uploader_area');
64
+        return EEH_HTML::div($input.EEH_HTML::nbsp().$uploader.$image, '', 'ee_media_uploader_area');
65 65
     }
66 66
 
67 67
 
Please login to merge, or discard this patch.
strategies/display/EE_Select_Multiple_Display_Strategy.strategy.php 2 patches
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -12,54 +12,54 @@
 block discarded – undo
12 12
 class EE_Select_Multiple_Display_Strategy extends EE_Select_Display_Strategy
13 13
 {
14 14
 
15
-    /**
16
-     *
17
-     * @throws EE_Error
18
-     * @return string of html to display the field
19
-     */
20
-    public function display()
21
-    {
15
+	/**
16
+	 *
17
+	 * @throws EE_Error
18
+	 * @return string of html to display the field
19
+	 */
20
+	public function display()
21
+	{
22 22
 
23
-        if (! $this->_input instanceof EE_Form_Input_With_Options_Base) {
24
-            throw new EE_Error(sprintf(esc_html__('Cannot use Select Multiple Display Strategy with an input that doesn\'t have options', "event_espresso")));
25
-        }
23
+		if (! $this->_input instanceof EE_Form_Input_With_Options_Base) {
24
+			throw new EE_Error(sprintf(esc_html__('Cannot use Select Multiple Display Strategy with an input that doesn\'t have options', "event_espresso")));
25
+		}
26 26
 
27
-        $html = EEH_HTML::nl(0, 'select');
28
-        $html .= '<select multiple';
29
-        $html .= ' id="' . $this->_input->html_id() . '"';
30
-        $html .= ' name="' . $this->_input->html_name() . '[]"';
31
-        $class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class();
32
-        $html .= ' class="' . $class . '"';
33
-        // add html5 required
34
-        $html .= $this->_input->required() ? ' required' : '';
35
-        $html .= ' style="' . $this->_input->html_style() . '"';
36
-        $html .= ' ' . $this->_input->other_html_attributes();
37
-        $html .= '>';
27
+		$html = EEH_HTML::nl(0, 'select');
28
+		$html .= '<select multiple';
29
+		$html .= ' id="' . $this->_input->html_id() . '"';
30
+		$html .= ' name="' . $this->_input->html_name() . '[]"';
31
+		$class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class();
32
+		$html .= ' class="' . $class . '"';
33
+		// add html5 required
34
+		$html .= $this->_input->required() ? ' required' : '';
35
+		$html .= ' style="' . $this->_input->html_style() . '"';
36
+		$html .= ' ' . $this->_input->other_html_attributes();
37
+		$html .= '>';
38 38
 
39
-        EEH_HTML::indent(1, 'select');
40
-        if (EEH_Array::is_multi_dimensional_array($this->_input->options())) {
41
-            throw new EE_Error(sprintf(esc_html__("Select multiple display strategy does not allow for nested arrays of options.", "event_espresso")));
42
-        } else {
43
-            $html .= $this->_display_options($this->_input->options());
44
-        }
39
+		EEH_HTML::indent(1, 'select');
40
+		if (EEH_Array::is_multi_dimensional_array($this->_input->options())) {
41
+			throw new EE_Error(sprintf(esc_html__("Select multiple display strategy does not allow for nested arrays of options.", "event_espresso")));
42
+		} else {
43
+			$html .= $this->_display_options($this->_input->options());
44
+		}
45 45
 
46
-        $html .= EEH_HTML::nl(-1, 'select') . "</select>";
47
-        return $html;
48
-    }
46
+		$html .= EEH_HTML::nl(-1, 'select') . "</select>";
47
+		return $html;
48
+	}
49 49
 
50 50
 
51 51
 
52
-    /**
53
-     * Checks if that $value is one of the selected ones
54
-     * @param string|int $value unnormalized value option (string)
55
-     * @return boolean
56
-     */
57
-    protected function _check_if_option_selected($value)
58
-    {
59
-        $selected_options = $this->_input->raw_value();
60
-        if (empty($selected_options)) {
61
-            return false;
62
-        }
63
-        return in_array($value, $selected_options) ? true : false;
64
-    }
52
+	/**
53
+	 * Checks if that $value is one of the selected ones
54
+	 * @param string|int $value unnormalized value option (string)
55
+	 * @return boolean
56
+	 */
57
+	protected function _check_if_option_selected($value)
58
+	{
59
+		$selected_options = $this->_input->raw_value();
60
+		if (empty($selected_options)) {
61
+			return false;
62
+		}
63
+		return in_array($value, $selected_options) ? true : false;
64
+	}
65 65
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -20,20 +20,20 @@  discard block
 block discarded – undo
20 20
     public function display()
21 21
     {
22 22
 
23
-        if (! $this->_input instanceof EE_Form_Input_With_Options_Base) {
23
+        if ( ! $this->_input instanceof EE_Form_Input_With_Options_Base) {
24 24
             throw new EE_Error(sprintf(esc_html__('Cannot use Select Multiple Display Strategy with an input that doesn\'t have options', "event_espresso")));
25 25
         }
26 26
 
27 27
         $html = EEH_HTML::nl(0, 'select');
28 28
         $html .= '<select multiple';
29
-        $html .= ' id="' . $this->_input->html_id() . '"';
30
-        $html .= ' name="' . $this->_input->html_name() . '[]"';
31
-        $class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class();
32
-        $html .= ' class="' . $class . '"';
29
+        $html .= ' id="'.$this->_input->html_id().'"';
30
+        $html .= ' name="'.$this->_input->html_name().'[]"';
31
+        $class = $this->_input->required() ? $this->_input->required_css_class().' '.$this->_input->html_class() : $this->_input->html_class();
32
+        $html .= ' class="'.$class.'"';
33 33
         // add html5 required
34 34
         $html .= $this->_input->required() ? ' required' : '';
35
-        $html .= ' style="' . $this->_input->html_style() . '"';
36
-        $html .= ' ' . $this->_input->other_html_attributes();
35
+        $html .= ' style="'.$this->_input->html_style().'"';
36
+        $html .= ' '.$this->_input->other_html_attributes();
37 37
         $html .= '>';
38 38
 
39 39
         EEH_HTML::indent(1, 'select');
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
             $html .= $this->_display_options($this->_input->options());
44 44
         }
45 45
 
46
-        $html .= EEH_HTML::nl(-1, 'select') . "</select>";
46
+        $html .= EEH_HTML::nl(-1, 'select')."</select>";
47 47
         return $html;
48 48
     }
49 49
 
Please login to merge, or discard this patch.
form_sections/strategies/display/EE_Select_Display_Strategy.strategy.php 2 patches
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -15,78 +15,78 @@
 block discarded – undo
15 15
 class EE_Select_Display_Strategy extends EE_Display_Strategy_Base
16 16
 {
17 17
 
18
-    /**
19
-     *
20
-     * @throws EE_Error
21
-     * @return string of html to display the field
22
-     */
23
-    public function display()
24
-    {
25
-        if (! $this->_input instanceof EE_Form_Input_With_Options_Base) {
26
-            throw new EE_Error(sprintf(esc_html__('Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso')));
27
-        }
18
+	/**
19
+	 *
20
+	 * @throws EE_Error
21
+	 * @return string of html to display the field
22
+	 */
23
+	public function display()
24
+	{
25
+		if (! $this->_input instanceof EE_Form_Input_With_Options_Base) {
26
+			throw new EE_Error(sprintf(esc_html__('Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso')));
27
+		}
28 28
 
29
-        $html = EEH_HTML::nl(0, 'select');
30
-        $html .= '<select';
31
-        $html .= $this->_attributes_string(
32
-            $this->_standard_attributes_array()
33
-        );
34
-        $html .= '>';
29
+		$html = EEH_HTML::nl(0, 'select');
30
+		$html .= '<select';
31
+		$html .= $this->_attributes_string(
32
+			$this->_standard_attributes_array()
33
+		);
34
+		$html .= '>';
35 35
 
36
-        if (EEH_Array::is_multi_dimensional_array($this->_input->options())) {
37
-            EEH_HTML::indent(1, 'optgroup');
38
-            foreach ($this->_input->options() as $opt_group_label => $opt_group) {
39
-                if (! empty($opt_group_label)) {
40
-                    $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">';
41
-                }
42
-                EEH_HTML::indent(1, 'option');
43
-                $html .= $this->_display_options($opt_group);
44
-                EEH_HTML::indent(-1, 'option');
45
-                if (! empty($opt_group_label)) {
46
-                    $html .= EEH_HTML::nl(0, 'optgroup') . '</optgroup>';
47
-                }
48
-            }
49
-            EEH_HTML::indent(-1, 'optgroup');
50
-        } else {
51
-            $html .= $this->_display_options($this->_input->options());
52
-        }
36
+		if (EEH_Array::is_multi_dimensional_array($this->_input->options())) {
37
+			EEH_HTML::indent(1, 'optgroup');
38
+			foreach ($this->_input->options() as $opt_group_label => $opt_group) {
39
+				if (! empty($opt_group_label)) {
40
+					$html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">';
41
+				}
42
+				EEH_HTML::indent(1, 'option');
43
+				$html .= $this->_display_options($opt_group);
44
+				EEH_HTML::indent(-1, 'option');
45
+				if (! empty($opt_group_label)) {
46
+					$html .= EEH_HTML::nl(0, 'optgroup') . '</optgroup>';
47
+				}
48
+			}
49
+			EEH_HTML::indent(-1, 'optgroup');
50
+		} else {
51
+			$html .= $this->_display_options($this->_input->options());
52
+		}
53 53
 
54
-        $html .= EEH_HTML::nl(0, 'select') . '</select>';
55
-        return $html;
56
-    }
54
+		$html .= EEH_HTML::nl(0, 'select') . '</select>';
55
+		return $html;
56
+	}
57 57
 
58 58
 
59 59
 
60
-    /**
61
-     * Displays a flat list of options as option tags
62
-     * @param array $options
63
-     * @return string
64
-     */
65
-    protected function _display_options($options)
66
-    {
67
-        $html = '';
68
-        EEH_HTML::indent(1, 'option');
69
-        foreach ($options as $value => $display_text) {
70
-            // even if this input uses EE_Text_Normalization if one of the array keys is a numeric string, like "123",
71
-            // PHP will have converted it to a PHP integer (eg 123). So we need to make sure it's a string
72
-            $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one($value);
73
-            $selected = $this->_check_if_option_selected($unnormalized_value) ? ' selected="selected"' : '';
74
-            $html .= EEH_HTML::nl(0, 'option') . '<option value="' . esc_attr($unnormalized_value) . '"' . $selected . '>' . $display_text . '</option>';
75
-        }
76
-        EEH_HTML::indent(-1, 'option');
77
-        return $html;
78
-    }
60
+	/**
61
+	 * Displays a flat list of options as option tags
62
+	 * @param array $options
63
+	 * @return string
64
+	 */
65
+	protected function _display_options($options)
66
+	{
67
+		$html = '';
68
+		EEH_HTML::indent(1, 'option');
69
+		foreach ($options as $value => $display_text) {
70
+			// even if this input uses EE_Text_Normalization if one of the array keys is a numeric string, like "123",
71
+			// PHP will have converted it to a PHP integer (eg 123). So we need to make sure it's a string
72
+			$unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one($value);
73
+			$selected = $this->_check_if_option_selected($unnormalized_value) ? ' selected="selected"' : '';
74
+			$html .= EEH_HTML::nl(0, 'option') . '<option value="' . esc_attr($unnormalized_value) . '"' . $selected . '>' . $display_text . '</option>';
75
+		}
76
+		EEH_HTML::indent(-1, 'option');
77
+		return $html;
78
+	}
79 79
 
80 80
 
81 81
 
82
-    /**
83
-     * Checks if that value is the one selected
84
-     *
85
-     * @param string|int $option_value unnormalized value option (string). How it will appear in the HTML.
86
-     * @return string
87
-     */
88
-    protected function _check_if_option_selected($option_value)
89
-    {
90
-        return $option_value === $this->_input->raw_value();
91
-    }
82
+	/**
83
+	 * Checks if that value is the one selected
84
+	 *
85
+	 * @param string|int $option_value unnormalized value option (string). How it will appear in the HTML.
86
+	 * @return string
87
+	 */
88
+	protected function _check_if_option_selected($option_value)
89
+	{
90
+		return $option_value === $this->_input->raw_value();
91
+	}
92 92
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
      */
23 23
     public function display()
24 24
     {
25
-        if (! $this->_input instanceof EE_Form_Input_With_Options_Base) {
25
+        if ( ! $this->_input instanceof EE_Form_Input_With_Options_Base) {
26 26
             throw new EE_Error(sprintf(esc_html__('Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso')));
27 27
         }
28 28
 
@@ -36,14 +36,14 @@  discard block
 block discarded – undo
36 36
         if (EEH_Array::is_multi_dimensional_array($this->_input->options())) {
37 37
             EEH_HTML::indent(1, 'optgroup');
38 38
             foreach ($this->_input->options() as $opt_group_label => $opt_group) {
39
-                if (! empty($opt_group_label)) {
40
-                    $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">';
39
+                if ( ! empty($opt_group_label)) {
40
+                    $html .= EEH_HTML::nl(0, 'optgroup').'<optgroup label="'.esc_attr($opt_group_label).'">';
41 41
                 }
42 42
                 EEH_HTML::indent(1, 'option');
43 43
                 $html .= $this->_display_options($opt_group);
44 44
                 EEH_HTML::indent(-1, 'option');
45
-                if (! empty($opt_group_label)) {
46
-                    $html .= EEH_HTML::nl(0, 'optgroup') . '</optgroup>';
45
+                if ( ! empty($opt_group_label)) {
46
+                    $html .= EEH_HTML::nl(0, 'optgroup').'</optgroup>';
47 47
                 }
48 48
             }
49 49
             EEH_HTML::indent(-1, 'optgroup');
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
             $html .= $this->_display_options($this->_input->options());
52 52
         }
53 53
 
54
-        $html .= EEH_HTML::nl(0, 'select') . '</select>';
54
+        $html .= EEH_HTML::nl(0, 'select').'</select>';
55 55
         return $html;
56 56
     }
57 57
 
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
             // PHP will have converted it to a PHP integer (eg 123). So we need to make sure it's a string
72 72
             $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one($value);
73 73
             $selected = $this->_check_if_option_selected($unnormalized_value) ? ' selected="selected"' : '';
74
-            $html .= EEH_HTML::nl(0, 'option') . '<option value="' . esc_attr($unnormalized_value) . '"' . $selected . '>' . $display_text . '</option>';
74
+            $html .= EEH_HTML::nl(0, 'option').'<option value="'.esc_attr($unnormalized_value).'"'.$selected.'>'.$display_text.'</option>';
75 75
         }
76 76
         EEH_HTML::indent(-1, 'option');
77 77
         return $html;
Please login to merge, or discard this patch.