Completed
Branch 973/fix-visible-recaptcha (0580c7)
by
unknown
03:03 queued 30s
created
libraries/form_sections/inputs/EE_Form_Input_With_Options_Base.input.php 2 patches
Indentation   +320 added lines, -320 removed lines patch added patch discarded remove patch
@@ -12,324 +12,324 @@
 block discarded – undo
12 12
 class EE_Form_Input_With_Options_Base extends EE_Form_Input_Base
13 13
 {
14 14
 
15
-    /**
16
-     * array of available options to choose as an answer
17
-     *
18
-     * @var array
19
-     */
20
-    protected $_options = array();
21
-
22
-    /**
23
-     * whether to display the html_label_text above the checkbox/radio button options
24
-     *
25
-     * @var boolean
26
-     */
27
-    protected $_display_html_label_text = true;
28
-
29
-    /**
30
-     * whether to display an question option description as part of the input label
31
-     *
32
-     * @var boolean
33
-     */
34
-    protected $_use_desc_in_label = true;
35
-
36
-    /**
37
-     * strlen() result for the longest input value (what gets displayed in the label)
38
-     * this is used to apply a css class to the input label
39
-     *
40
-     * @var int
41
-     */
42
-    protected $_label_size = 0;
43
-
44
-    /**
45
-     * whether to enforce the label size value passed in the constructor
46
-     *
47
-     * @var boolean
48
-     */
49
-    protected $_enforce_label_size = false;
50
-
51
-    /**
52
-     * whether to allow multiple selections (ie, the value of this input should be an array)
53
-     * or not (ie, the value should be a simple int, string, etc)
54
-     *
55
-     * @var boolean
56
-     */
57
-    protected $_multiple_selections = false;
58
-
59
-
60
-
61
-    /**
62
-     * @param array     $answer_options
63
-     * @param array     $input_settings {
64
-     * @type int|string $label_size
65
-     * @type boolean    $display_html_label_text
66
-     *                                  }
67
-     *                                  And all the options accepted by EE_Form_Input_Base
68
-     */
69
-    public function __construct($answer_options = array(), $input_settings = array())
70
-    {
71
-        if (isset($input_settings['label_size'])) {
72
-            $this->_set_label_size($input_settings['label_size']);
73
-            if (isset($input_settings['enforce_label_size']) && $input_settings['enforce_label_size']) {
74
-                $this->_enforce_label_size = true;
75
-            }
76
-        }
77
-        if (isset($input_settings['display_html_label_text'])) {
78
-            $this->set_display_html_label_text($input_settings['display_html_label_text']);
79
-        }
80
-        $this->set_select_options($answer_options);
81
-        parent::__construct($input_settings);
82
-    }
83
-
84
-
85
-
86
-    /**
87
-     * Sets the allowed options for this input. Also has the side-effect of
88
-     * updating the normalization strategy to match the keys provided in the array
89
-     *
90
-     * @param array $answer_options
91
-     * @return void  just has the side-effect of setting the options for this input
92
-     */
93
-    public function set_select_options($answer_options = array())
94
-    {
95
-        $answer_options = is_array($answer_options) ? $answer_options : array($answer_options);
96
-        // get the first item in the select options and check it's type
97
-        $this->_options = reset($answer_options) instanceof EE_Question_Option
98
-            ? $this->_process_question_options($answer_options)
99
-            : $answer_options;
100
-        // d( $this->_options );
101
-        $select_option_keys = array_keys($this->_options);
102
-        // attempt to determine data type for values in order to set normalization type
103
-        // purposefully only
104
-        if (
105
-            count($this->_options) === 2
106
-            && (
107
-                (in_array(true, $select_option_keys, true) && in_array(false, $select_option_keys, true))
108
-                || (in_array(1, $select_option_keys, true) && in_array(0, $select_option_keys, true))
109
-            )
110
-        ) {
111
-            // values appear to be boolean, like TRUE, FALSE, 1, 0
112
-            $normalization = new EE_Boolean_Normalization();
113
-        } else {
114
-            // are ALL the options ints (even if we're using a multi-dimensional array)? If so use int validation
115
-            $all_ints = true;
116
-            array_walk_recursive(
117
-                $this->_options,
118
-                function ($value, $key) use (&$all_ints) {
119
-                    // is this a top-level key? ignore it
120
-                    if (
121
-                        ! is_array($value)
122
-                        && ! is_int($key)
123
-                        && $key !== ''
124
-                        && $key !== null
125
-                    ) {
126
-                        $all_ints = false;
127
-                    }
128
-                }
129
-            );
130
-            if ($all_ints) {
131
-                $normalization = new EE_Int_Normalization();
132
-            } else {
133
-                $normalization = new EE_Text_Normalization();
134
-            }
135
-        }
136
-        // does input type have multiple options ?
137
-        if ($this->_multiple_selections) {
138
-            $this->_set_normalization_strategy(new EE_Many_Valued_Normalization($normalization));
139
-        } else {
140
-            $this->_set_normalization_strategy($normalization);
141
-        }
142
-    }
143
-
144
-
145
-
146
-    /**
147
-     * @return array
148
-     */
149
-    public function options()
150
-    {
151
-        return $this->_options;
152
-    }
153
-
154
-
155
-
156
-    /**
157
-     * Returns an array which is guaranteed to not be multidimensional
158
-     *
159
-     * @return array
160
-     */
161
-    public function flat_options()
162
-    {
163
-        return $this->_flatten_select_options($this->options());
164
-    }
165
-
166
-
167
-
168
-    /**
169
-     * Makes sure $arr is a flat array, not a multidimensional one
170
-     *
171
-     * @param array $arr
172
-     * @return array
173
-     */
174
-    protected function _flatten_select_options($arr)
175
-    {
176
-        $flat_array = array();
177
-        if (EEH_Array::is_multi_dimensional_array($arr)) {
178
-            foreach ($arr as $sub_array) {
179
-                foreach ((array) $sub_array as $key => $value) {
180
-                    $flat_array[ $key ] = $value;
181
-                    $this->_set_label_size($value);
182
-                }
183
-            }
184
-        } else {
185
-            foreach ($arr as $key => $value) {
186
-                $flat_array[ $key ] = $value;
187
-                $this->_set_label_size($value);
188
-            }
189
-        }
190
-        return $flat_array;
191
-    }
192
-
193
-
194
-
195
-    /**
196
-     * @param EE_Question_Option[] $question_options_array
197
-     * @return array
198
-     */
199
-    protected function _process_question_options($question_options_array = array())
200
-    {
201
-        $flat_array = array();
202
-        foreach ($question_options_array as $question_option) {
203
-            if ($question_option instanceof EE_Question_Option) {
204
-                $desc = '';
205
-                if ($this->_use_desc_in_label) {
206
-                    $desc = $question_option->desc();
207
-                    $desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : '';
208
-                }
209
-                $value = $question_option->value();
210
-                // add value even if it's empty
211
-                $flat_array[ $value ] = $value;
212
-                // if both value and desc are not empty, then separate with a dash
213
-                if (! empty($value) && ! empty($desc)) {
214
-                    $flat_array[ $value ] .= ' - ' . $desc;
215
-                } else {
216
-                    // otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary
217
-                    $flat_array[ $value ] .= $desc;
218
-                }
219
-            } elseif (is_array($question_option)) {
220
-                $flat_array += $this->_flatten_select_options($question_option);
221
-            }
222
-        }
223
-        return $flat_array;
224
-    }
225
-
226
-
227
-
228
-    /**
229
-     *    set_label_sizes
230
-     *
231
-     * @return void
232
-     */
233
-    public function set_label_sizes()
234
-    {
235
-        // did the input settings specifically say to NOT set the label size dynamically ?
236
-        if (! $this->_enforce_label_size) {
237
-            foreach ($this->_options as $option) {
238
-                // calculate the strlen of the label
239
-                $this->_set_label_size($option);
240
-            }
241
-        }
242
-    }
243
-
244
-
245
-
246
-    /**
247
-     *    _set_label_size_class
248
-     *
249
-     * @param int|string $value
250
-     * @return void
251
-     */
252
-    private function _set_label_size($value = '')
253
-    {
254
-        // don't change label size if it has already been set and is being enforced
255
-        if ($this->_enforce_label_size && $this->_label_size >  0) {
256
-            return;
257
-        }
258
-        // determine length of option value
259
-        $val_size = is_int($value) ? $value : strlen($value);
260
-        // use new value if bigger than existing
261
-        $this->_label_size = $val_size > $this->_label_size ? $val_size : $this->_label_size;
262
-    }
263
-
264
-
265
-
266
-    /**
267
-     *    get_label_size_class
268
-     *
269
-     * @return string
270
-     */
271
-    public function get_label_size_class()
272
-    {
273
-        $size = ' medium-lbl';
274
-        // use maximum option value length to determine label size
275
-        if ($this->_label_size < 3) {
276
-            $size = ' nano-lbl';
277
-        } elseif ($this->_label_size < 6) {
278
-            $size = ' micro-lbl';
279
-        } elseif ($this->_label_size < 12) {
280
-            $size = ' tiny-lbl';
281
-        } elseif ($this->_label_size < 25) {
282
-            $size = ' small-lbl';
283
-        } elseif ($this->_label_size < 50) {
284
-            $size = ' medium-lbl';
285
-        } elseif ($this->_label_size >= 100) {
286
-            $size = ' big-lbl';
287
-        }
288
-        return $size;
289
-    }
290
-
291
-
292
-
293
-    /**
294
-     * Returns the pretty value for the normalized value
295
-     *
296
-     * @return string
297
-     */
298
-    public function pretty_value()
299
-    {
300
-        $options = $this->flat_options();
301
-        $unnormalized_value_choices = $this->get_normalization_strategy()->unnormalize($this->_normalized_value);
302
-        if (! $this->_multiple_selections) {
303
-            $unnormalized_value_choices = array($unnormalized_value_choices);
304
-        }
305
-        $pretty_strings = array();
306
-        foreach ((array) $unnormalized_value_choices as $unnormalized_value_choice) {
307
-            if (isset($options[ $unnormalized_value_choice ])) {
308
-                $pretty_strings[] = $options[ $unnormalized_value_choice ];
309
-            } else {
310
-                $pretty_strings[] = $this->normalized_value();
311
-            }
312
-        }
313
-        return implode(', ', $pretty_strings);
314
-    }
315
-
316
-
317
-
318
-    /**
319
-     * @return boolean
320
-     */
321
-    public function display_html_label_text()
322
-    {
323
-        return $this->_display_html_label_text;
324
-    }
325
-
326
-
327
-
328
-    /**
329
-     * @param boolean $display_html_label_text
330
-     */
331
-    public function set_display_html_label_text($display_html_label_text)
332
-    {
333
-        $this->_display_html_label_text = filter_var($display_html_label_text, FILTER_VALIDATE_BOOLEAN);
334
-    }
15
+	/**
16
+	 * array of available options to choose as an answer
17
+	 *
18
+	 * @var array
19
+	 */
20
+	protected $_options = array();
21
+
22
+	/**
23
+	 * whether to display the html_label_text above the checkbox/radio button options
24
+	 *
25
+	 * @var boolean
26
+	 */
27
+	protected $_display_html_label_text = true;
28
+
29
+	/**
30
+	 * whether to display an question option description as part of the input label
31
+	 *
32
+	 * @var boolean
33
+	 */
34
+	protected $_use_desc_in_label = true;
35
+
36
+	/**
37
+	 * strlen() result for the longest input value (what gets displayed in the label)
38
+	 * this is used to apply a css class to the input label
39
+	 *
40
+	 * @var int
41
+	 */
42
+	protected $_label_size = 0;
43
+
44
+	/**
45
+	 * whether to enforce the label size value passed in the constructor
46
+	 *
47
+	 * @var boolean
48
+	 */
49
+	protected $_enforce_label_size = false;
50
+
51
+	/**
52
+	 * whether to allow multiple selections (ie, the value of this input should be an array)
53
+	 * or not (ie, the value should be a simple int, string, etc)
54
+	 *
55
+	 * @var boolean
56
+	 */
57
+	protected $_multiple_selections = false;
58
+
59
+
60
+
61
+	/**
62
+	 * @param array     $answer_options
63
+	 * @param array     $input_settings {
64
+	 * @type int|string $label_size
65
+	 * @type boolean    $display_html_label_text
66
+	 *                                  }
67
+	 *                                  And all the options accepted by EE_Form_Input_Base
68
+	 */
69
+	public function __construct($answer_options = array(), $input_settings = array())
70
+	{
71
+		if (isset($input_settings['label_size'])) {
72
+			$this->_set_label_size($input_settings['label_size']);
73
+			if (isset($input_settings['enforce_label_size']) && $input_settings['enforce_label_size']) {
74
+				$this->_enforce_label_size = true;
75
+			}
76
+		}
77
+		if (isset($input_settings['display_html_label_text'])) {
78
+			$this->set_display_html_label_text($input_settings['display_html_label_text']);
79
+		}
80
+		$this->set_select_options($answer_options);
81
+		parent::__construct($input_settings);
82
+	}
83
+
84
+
85
+
86
+	/**
87
+	 * Sets the allowed options for this input. Also has the side-effect of
88
+	 * updating the normalization strategy to match the keys provided in the array
89
+	 *
90
+	 * @param array $answer_options
91
+	 * @return void  just has the side-effect of setting the options for this input
92
+	 */
93
+	public function set_select_options($answer_options = array())
94
+	{
95
+		$answer_options = is_array($answer_options) ? $answer_options : array($answer_options);
96
+		// get the first item in the select options and check it's type
97
+		$this->_options = reset($answer_options) instanceof EE_Question_Option
98
+			? $this->_process_question_options($answer_options)
99
+			: $answer_options;
100
+		// d( $this->_options );
101
+		$select_option_keys = array_keys($this->_options);
102
+		// attempt to determine data type for values in order to set normalization type
103
+		// purposefully only
104
+		if (
105
+			count($this->_options) === 2
106
+			&& (
107
+				(in_array(true, $select_option_keys, true) && in_array(false, $select_option_keys, true))
108
+				|| (in_array(1, $select_option_keys, true) && in_array(0, $select_option_keys, true))
109
+			)
110
+		) {
111
+			// values appear to be boolean, like TRUE, FALSE, 1, 0
112
+			$normalization = new EE_Boolean_Normalization();
113
+		} else {
114
+			// are ALL the options ints (even if we're using a multi-dimensional array)? If so use int validation
115
+			$all_ints = true;
116
+			array_walk_recursive(
117
+				$this->_options,
118
+				function ($value, $key) use (&$all_ints) {
119
+					// is this a top-level key? ignore it
120
+					if (
121
+						! is_array($value)
122
+						&& ! is_int($key)
123
+						&& $key !== ''
124
+						&& $key !== null
125
+					) {
126
+						$all_ints = false;
127
+					}
128
+				}
129
+			);
130
+			if ($all_ints) {
131
+				$normalization = new EE_Int_Normalization();
132
+			} else {
133
+				$normalization = new EE_Text_Normalization();
134
+			}
135
+		}
136
+		// does input type have multiple options ?
137
+		if ($this->_multiple_selections) {
138
+			$this->_set_normalization_strategy(new EE_Many_Valued_Normalization($normalization));
139
+		} else {
140
+			$this->_set_normalization_strategy($normalization);
141
+		}
142
+	}
143
+
144
+
145
+
146
+	/**
147
+	 * @return array
148
+	 */
149
+	public function options()
150
+	{
151
+		return $this->_options;
152
+	}
153
+
154
+
155
+
156
+	/**
157
+	 * Returns an array which is guaranteed to not be multidimensional
158
+	 *
159
+	 * @return array
160
+	 */
161
+	public function flat_options()
162
+	{
163
+		return $this->_flatten_select_options($this->options());
164
+	}
165
+
166
+
167
+
168
+	/**
169
+	 * Makes sure $arr is a flat array, not a multidimensional one
170
+	 *
171
+	 * @param array $arr
172
+	 * @return array
173
+	 */
174
+	protected function _flatten_select_options($arr)
175
+	{
176
+		$flat_array = array();
177
+		if (EEH_Array::is_multi_dimensional_array($arr)) {
178
+			foreach ($arr as $sub_array) {
179
+				foreach ((array) $sub_array as $key => $value) {
180
+					$flat_array[ $key ] = $value;
181
+					$this->_set_label_size($value);
182
+				}
183
+			}
184
+		} else {
185
+			foreach ($arr as $key => $value) {
186
+				$flat_array[ $key ] = $value;
187
+				$this->_set_label_size($value);
188
+			}
189
+		}
190
+		return $flat_array;
191
+	}
192
+
193
+
194
+
195
+	/**
196
+	 * @param EE_Question_Option[] $question_options_array
197
+	 * @return array
198
+	 */
199
+	protected function _process_question_options($question_options_array = array())
200
+	{
201
+		$flat_array = array();
202
+		foreach ($question_options_array as $question_option) {
203
+			if ($question_option instanceof EE_Question_Option) {
204
+				$desc = '';
205
+				if ($this->_use_desc_in_label) {
206
+					$desc = $question_option->desc();
207
+					$desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : '';
208
+				}
209
+				$value = $question_option->value();
210
+				// add value even if it's empty
211
+				$flat_array[ $value ] = $value;
212
+				// if both value and desc are not empty, then separate with a dash
213
+				if (! empty($value) && ! empty($desc)) {
214
+					$flat_array[ $value ] .= ' - ' . $desc;
215
+				} else {
216
+					// otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary
217
+					$flat_array[ $value ] .= $desc;
218
+				}
219
+			} elseif (is_array($question_option)) {
220
+				$flat_array += $this->_flatten_select_options($question_option);
221
+			}
222
+		}
223
+		return $flat_array;
224
+	}
225
+
226
+
227
+
228
+	/**
229
+	 *    set_label_sizes
230
+	 *
231
+	 * @return void
232
+	 */
233
+	public function set_label_sizes()
234
+	{
235
+		// did the input settings specifically say to NOT set the label size dynamically ?
236
+		if (! $this->_enforce_label_size) {
237
+			foreach ($this->_options as $option) {
238
+				// calculate the strlen of the label
239
+				$this->_set_label_size($option);
240
+			}
241
+		}
242
+	}
243
+
244
+
245
+
246
+	/**
247
+	 *    _set_label_size_class
248
+	 *
249
+	 * @param int|string $value
250
+	 * @return void
251
+	 */
252
+	private function _set_label_size($value = '')
253
+	{
254
+		// don't change label size if it has already been set and is being enforced
255
+		if ($this->_enforce_label_size && $this->_label_size >  0) {
256
+			return;
257
+		}
258
+		// determine length of option value
259
+		$val_size = is_int($value) ? $value : strlen($value);
260
+		// use new value if bigger than existing
261
+		$this->_label_size = $val_size > $this->_label_size ? $val_size : $this->_label_size;
262
+	}
263
+
264
+
265
+
266
+	/**
267
+	 *    get_label_size_class
268
+	 *
269
+	 * @return string
270
+	 */
271
+	public function get_label_size_class()
272
+	{
273
+		$size = ' medium-lbl';
274
+		// use maximum option value length to determine label size
275
+		if ($this->_label_size < 3) {
276
+			$size = ' nano-lbl';
277
+		} elseif ($this->_label_size < 6) {
278
+			$size = ' micro-lbl';
279
+		} elseif ($this->_label_size < 12) {
280
+			$size = ' tiny-lbl';
281
+		} elseif ($this->_label_size < 25) {
282
+			$size = ' small-lbl';
283
+		} elseif ($this->_label_size < 50) {
284
+			$size = ' medium-lbl';
285
+		} elseif ($this->_label_size >= 100) {
286
+			$size = ' big-lbl';
287
+		}
288
+		return $size;
289
+	}
290
+
291
+
292
+
293
+	/**
294
+	 * Returns the pretty value for the normalized value
295
+	 *
296
+	 * @return string
297
+	 */
298
+	public function pretty_value()
299
+	{
300
+		$options = $this->flat_options();
301
+		$unnormalized_value_choices = $this->get_normalization_strategy()->unnormalize($this->_normalized_value);
302
+		if (! $this->_multiple_selections) {
303
+			$unnormalized_value_choices = array($unnormalized_value_choices);
304
+		}
305
+		$pretty_strings = array();
306
+		foreach ((array) $unnormalized_value_choices as $unnormalized_value_choice) {
307
+			if (isset($options[ $unnormalized_value_choice ])) {
308
+				$pretty_strings[] = $options[ $unnormalized_value_choice ];
309
+			} else {
310
+				$pretty_strings[] = $this->normalized_value();
311
+			}
312
+		}
313
+		return implode(', ', $pretty_strings);
314
+	}
315
+
316
+
317
+
318
+	/**
319
+	 * @return boolean
320
+	 */
321
+	public function display_html_label_text()
322
+	{
323
+		return $this->_display_html_label_text;
324
+	}
325
+
326
+
327
+
328
+	/**
329
+	 * @param boolean $display_html_label_text
330
+	 */
331
+	public function set_display_html_label_text($display_html_label_text)
332
+	{
333
+		$this->_display_html_label_text = filter_var($display_html_label_text, FILTER_VALIDATE_BOOLEAN);
334
+	}
335 335
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
             $all_ints = true;
116 116
             array_walk_recursive(
117 117
                 $this->_options,
118
-                function ($value, $key) use (&$all_ints) {
118
+                function($value, $key) use (&$all_ints) {
119 119
                     // is this a top-level key? ignore it
120 120
                     if (
121 121
                         ! is_array($value)
@@ -177,13 +177,13 @@  discard block
 block discarded – undo
177 177
         if (EEH_Array::is_multi_dimensional_array($arr)) {
178 178
             foreach ($arr as $sub_array) {
179 179
                 foreach ((array) $sub_array as $key => $value) {
180
-                    $flat_array[ $key ] = $value;
180
+                    $flat_array[$key] = $value;
181 181
                     $this->_set_label_size($value);
182 182
                 }
183 183
             }
184 184
         } else {
185 185
             foreach ($arr as $key => $value) {
186
-                $flat_array[ $key ] = $value;
186
+                $flat_array[$key] = $value;
187 187
                 $this->_set_label_size($value);
188 188
             }
189 189
         }
@@ -204,17 +204,17 @@  discard block
 block discarded – undo
204 204
                 $desc = '';
205 205
                 if ($this->_use_desc_in_label) {
206 206
                     $desc = $question_option->desc();
207
-                    $desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : '';
207
+                    $desc = ! empty($desc) ? '<span class="ee-question-option-desc">'.$desc.'</span>' : '';
208 208
                 }
209 209
                 $value = $question_option->value();
210 210
                 // add value even if it's empty
211
-                $flat_array[ $value ] = $value;
211
+                $flat_array[$value] = $value;
212 212
                 // if both value and desc are not empty, then separate with a dash
213
-                if (! empty($value) && ! empty($desc)) {
214
-                    $flat_array[ $value ] .= ' - ' . $desc;
213
+                if ( ! empty($value) && ! empty($desc)) {
214
+                    $flat_array[$value] .= ' - '.$desc;
215 215
                 } else {
216 216
                     // otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary
217
-                    $flat_array[ $value ] .= $desc;
217
+                    $flat_array[$value] .= $desc;
218 218
                 }
219 219
             } elseif (is_array($question_option)) {
220 220
                 $flat_array += $this->_flatten_select_options($question_option);
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
     public function set_label_sizes()
234 234
     {
235 235
         // did the input settings specifically say to NOT set the label size dynamically ?
236
-        if (! $this->_enforce_label_size) {
236
+        if ( ! $this->_enforce_label_size) {
237 237
             foreach ($this->_options as $option) {
238 238
                 // calculate the strlen of the label
239 239
                 $this->_set_label_size($option);
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
     private function _set_label_size($value = '')
253 253
     {
254 254
         // don't change label size if it has already been set and is being enforced
255
-        if ($this->_enforce_label_size && $this->_label_size >  0) {
255
+        if ($this->_enforce_label_size && $this->_label_size > 0) {
256 256
             return;
257 257
         }
258 258
         // determine length of option value
@@ -299,13 +299,13 @@  discard block
 block discarded – undo
299 299
     {
300 300
         $options = $this->flat_options();
301 301
         $unnormalized_value_choices = $this->get_normalization_strategy()->unnormalize($this->_normalized_value);
302
-        if (! $this->_multiple_selections) {
302
+        if ( ! $this->_multiple_selections) {
303 303
             $unnormalized_value_choices = array($unnormalized_value_choices);
304 304
         }
305 305
         $pretty_strings = array();
306 306
         foreach ((array) $unnormalized_value_choices as $unnormalized_value_choice) {
307
-            if (isset($options[ $unnormalized_value_choice ])) {
308
-                $pretty_strings[] = $options[ $unnormalized_value_choice ];
307
+            if (isset($options[$unnormalized_value_choice])) {
308
+                $pretty_strings[] = $options[$unnormalized_value_choice];
309 309
             } else {
310 310
                 $pretty_strings[] = $this->normalized_value();
311 311
             }
Please login to merge, or discard this patch.
strategies/display/EE_Text_Input_Display_Strategy.strategy.php 2 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -14,59 +14,59 @@
 block discarded – undo
14 14
  */
15 15
 class EE_Text_Input_Display_Strategy extends EE_Display_Strategy_Base
16 16
 {
17
-    /**
18
-     * The html "type" attribute value. default is "text"
19
-     * @var string
20
-     */
21
-    protected $_type;
17
+	/**
18
+	 * The html "type" attribute value. default is "text"
19
+	 * @var string
20
+	 */
21
+	protected $_type;
22 22
 
23 23
 
24 24
 
25
-    /**
26
-     * @param string $type
27
-     */
28
-    public function __construct($type = 'text')
29
-    {
30
-        $this->_type = $type;
31
-        parent::__construct();
32
-    }
25
+	/**
26
+	 * @param string $type
27
+	 */
28
+	public function __construct($type = 'text')
29
+	{
30
+		$this->_type = $type;
31
+		parent::__construct();
32
+	}
33 33
 
34 34
 
35 35
 
36
-    /**
37
-     * Gets the html "type" attribute's value
38
-     * @return string
39
-     */
40
-    public function get_type()
41
-    {
42
-        if (
43
-            $this->_type === 'email'
44
-            && ! apply_filters('FHEE__EE_Text_Input_Display_Strategy__use_html5_email', false)
45
-        ) {
46
-            return 'text';
47
-        }
48
-        return $this->_type;
49
-    }
36
+	/**
37
+	 * Gets the html "type" attribute's value
38
+	 * @return string
39
+	 */
40
+	public function get_type()
41
+	{
42
+		if (
43
+			$this->_type === 'email'
44
+			&& ! apply_filters('FHEE__EE_Text_Input_Display_Strategy__use_html5_email', false)
45
+		) {
46
+			return 'text';
47
+		}
48
+		return $this->_type;
49
+	}
50 50
 
51 51
 
52 52
 
53
-    /**
54
-     *
55
-     * @return string of html to display the field
56
-     */
57
-    public function display()
58
-    {
59
-        $input = '<input type="' . $this->get_type() . '"';
60
-        $input .= ' name="' . $this->_input->html_name() . '"';
61
-        $input .= ' id="' . $this->_input->html_id() . '"';
62
-        $class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class();
63
-        $input .= ' class="' . $class . '"';
64
-        // add html5 required
65
-        $input .= $this->_input->required() ? ' required' : '';
66
-        $input .= ' value="' . $this->_input->raw_value_in_form() . '"';
67
-        $input .= ' style="' . $this->_input->html_style() . '"';
68
-        $input .= $this->_input->other_html_attributes();
69
-        $input .= '/>';
70
-        return $input;
71
-    }
53
+	/**
54
+	 *
55
+	 * @return string of html to display the field
56
+	 */
57
+	public function display()
58
+	{
59
+		$input = '<input type="' . $this->get_type() . '"';
60
+		$input .= ' name="' . $this->_input->html_name() . '"';
61
+		$input .= ' id="' . $this->_input->html_id() . '"';
62
+		$class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class();
63
+		$input .= ' class="' . $class . '"';
64
+		// add html5 required
65
+		$input .= $this->_input->required() ? ' required' : '';
66
+		$input .= ' value="' . $this->_input->raw_value_in_form() . '"';
67
+		$input .= ' style="' . $this->_input->html_style() . '"';
68
+		$input .= $this->_input->other_html_attributes();
69
+		$input .= '/>';
70
+		return $input;
71
+	}
72 72
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -56,15 +56,15 @@
 block discarded – undo
56 56
      */
57 57
     public function display()
58 58
     {
59
-        $input = '<input type="' . $this->get_type() . '"';
60
-        $input .= ' name="' . $this->_input->html_name() . '"';
61
-        $input .= ' id="' . $this->_input->html_id() . '"';
62
-        $class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class();
63
-        $input .= ' class="' . $class . '"';
59
+        $input = '<input type="'.$this->get_type().'"';
60
+        $input .= ' name="'.$this->_input->html_name().'"';
61
+        $input .= ' id="'.$this->_input->html_id().'"';
62
+        $class = $this->_input->required() ? $this->_input->required_css_class().' '.$this->_input->html_class() : $this->_input->html_class();
63
+        $input .= ' class="'.$class.'"';
64 64
         // add html5 required
65 65
         $input .= $this->_input->required() ? ' required' : '';
66
-        $input .= ' value="' . $this->_input->raw_value_in_form() . '"';
67
-        $input .= ' style="' . $this->_input->html_style() . '"';
66
+        $input .= ' value="'.$this->_input->raw_value_in_form().'"';
67
+        $input .= ' style="'.$this->_input->html_style().'"';
68 68
         $input .= $this->_input->other_html_attributes();
69 69
         $input .= '/>';
70 70
         return $input;
Please login to merge, or discard this patch.
sensitive_data_removal/EE_CCV_Sensitive_Data_Removal.strategy.php 2 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -11,18 +11,18 @@
 block discarded – undo
11 11
  */
12 12
 class EE_CCV_Sensitive_Data_Removal extends EE_Sensitive_Data_Removal_Base
13 13
 {
14
-    public function remove_sensitive_data($normalized_value)
15
-    {
16
-        // Get the ccv Length
17
-        $ccv_lenght = strlen($normalized_value);
18
-        // Replace all characters of credit card except the last four and dashes
19
-        for ($i = 0; $i < $ccv_lenght; $i++) {
20
-            if ($normalized_value[ $i ] == '-') {
21
-                continue;
22
-            }
23
-            $normalized_value[ $i ] = 'X';
24
-        }
25
-        // Return the masked Credit Card #
26
-        return $normalized_value;
27
-    }
14
+	public function remove_sensitive_data($normalized_value)
15
+	{
16
+		// Get the ccv Length
17
+		$ccv_lenght = strlen($normalized_value);
18
+		// Replace all characters of credit card except the last four and dashes
19
+		for ($i = 0; $i < $ccv_lenght; $i++) {
20
+			if ($normalized_value[ $i ] == '-') {
21
+				continue;
22
+			}
23
+			$normalized_value[ $i ] = 'X';
24
+		}
25
+		// Return the masked Credit Card #
26
+		return $normalized_value;
27
+	}
28 28
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -17,10 +17,10 @@
 block discarded – undo
17 17
         $ccv_lenght = strlen($normalized_value);
18 18
         // Replace all characters of credit card except the last four and dashes
19 19
         for ($i = 0; $i < $ccv_lenght; $i++) {
20
-            if ($normalized_value[ $i ] == '-') {
20
+            if ($normalized_value[$i] == '-') {
21 21
                 continue;
22 22
             }
23
-            $normalized_value[ $i ] = 'X';
23
+            $normalized_value[$i] = 'X';
24 24
         }
25 25
         // Return the masked Credit Card #
26 26
         return $normalized_value;
Please login to merge, or discard this patch.
sensitive_data_removal/EE_Credit_Card_Sensitive_Data_Removal.strategy.php 2 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -11,18 +11,18 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Credit_Card_Sensitive_Data_Removal extends EE_Sensitive_Data_Removal_Base
13 13
 {
14
-    public function remove_sensitive_data($normalized_value)
15
-    {
16
-        // Get the cc Length
17
-        $cc_length = strlen($normalized_value);
18
-        // Replace all characters of credit card except the last four and dashes
19
-        for ($i = 0; $i < $cc_length - 4; $i++) {
20
-            if ($normalized_value[ $i ] == '-') {
21
-                continue;
22
-            }
23
-            $normalized_value[ $i ] = 'X';
24
-        }
25
-        // Return the masked Credit Card #
26
-        return $normalized_value;
27
-    }
14
+	public function remove_sensitive_data($normalized_value)
15
+	{
16
+		// Get the cc Length
17
+		$cc_length = strlen($normalized_value);
18
+		// Replace all characters of credit card except the last four and dashes
19
+		for ($i = 0; $i < $cc_length - 4; $i++) {
20
+			if ($normalized_value[ $i ] == '-') {
21
+				continue;
22
+			}
23
+			$normalized_value[ $i ] = 'X';
24
+		}
25
+		// Return the masked Credit Card #
26
+		return $normalized_value;
27
+	}
28 28
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -17,10 +17,10 @@
 block discarded – undo
17 17
         $cc_length = strlen($normalized_value);
18 18
         // Replace all characters of credit card except the last four and dashes
19 19
         for ($i = 0; $i < $cc_length - 4; $i++) {
20
-            if ($normalized_value[ $i ] == '-') {
20
+            if ($normalized_value[$i] == '-') {
21 21
                 continue;
22 22
             }
23
-            $normalized_value[ $i ] = 'X';
23
+            $normalized_value[$i] = 'X';
24 24
         }
25 25
         // Return the masked Credit Card #
26 26
         return $normalized_value;
Please login to merge, or discard this patch.
strategies/validation/EE_Max_Length_Validation_Strategy.strategy.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@
 block discarded – undo
44 44
     public function get_jquery_validation_rule_array()
45 45
     {
46 46
         if ($this->_max_length !== EE_INF) {
47
-            return array( 'maxlength' => $this->_max_length, 'messages' => array( 'maxlength' => $this->get_validation_error_message() ) );
47
+            return array('maxlength' => $this->_max_length, 'messages' => array('maxlength' => $this->get_validation_error_message()));
48 48
         } else {
49 49
             return array();
50 50
         }
Please login to merge, or discard this patch.
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -12,41 +12,41 @@
 block discarded – undo
12 12
 class EE_Max_Length_Validation_Strategy extends EE_Validation_Strategy_Base
13 13
 {
14 14
 
15
-    protected $_max_length;
15
+	protected $_max_length;
16 16
 
17
-    public function __construct($validation_error_message = null, $max_length = EE_INF)
18
-    {
19
-        $this->_max_length = $max_length;
20
-        if ($validation_error_message === null) {
21
-            $validation_error_message = sprintf(esc_html__('Input is too long. Maximum number of characters is %1$s', 'event_espresso'), $max_length);
22
-        }
23
-        parent::__construct($validation_error_message);
24
-    }
17
+	public function __construct($validation_error_message = null, $max_length = EE_INF)
18
+	{
19
+		$this->_max_length = $max_length;
20
+		if ($validation_error_message === null) {
21
+			$validation_error_message = sprintf(esc_html__('Input is too long. Maximum number of characters is %1$s', 'event_espresso'), $max_length);
22
+		}
23
+		parent::__construct($validation_error_message);
24
+	}
25 25
 
26
-    /**
27
-     * @param $normalized_value
28
-     */
29
-    public function validate($normalized_value)
30
-    {
31
-        if (
32
-            $this->_max_length !== EE_INF &&
33
-                $normalized_value &&
34
-                is_string($normalized_value) &&
35
-                 strlen($normalized_value) > $this->_max_length
36
-        ) {
37
-            throw new EE_Validation_Error($this->get_validation_error_message(), 'maxlength');
38
-        }
39
-    }
26
+	/**
27
+	 * @param $normalized_value
28
+	 */
29
+	public function validate($normalized_value)
30
+	{
31
+		if (
32
+			$this->_max_length !== EE_INF &&
33
+				$normalized_value &&
34
+				is_string($normalized_value) &&
35
+				 strlen($normalized_value) > $this->_max_length
36
+		) {
37
+			throw new EE_Validation_Error($this->get_validation_error_message(), 'maxlength');
38
+		}
39
+	}
40 40
 
41
-    /**
42
-     * @return array
43
-     */
44
-    public function get_jquery_validation_rule_array()
45
-    {
46
-        if ($this->_max_length !== EE_INF) {
47
-            return array( 'maxlength' => $this->_max_length, 'messages' => array( 'maxlength' => $this->get_validation_error_message() ) );
48
-        } else {
49
-            return array();
50
-        }
51
-    }
41
+	/**
42
+	 * @return array
43
+	 */
44
+	public function get_jquery_validation_rule_array()
45
+	{
46
+		if ($this->_max_length !== EE_INF) {
47
+			return array( 'maxlength' => $this->_max_length, 'messages' => array( 'maxlength' => $this->get_validation_error_message() ) );
48
+		} else {
49
+			return array();
50
+		}
51
+	}
52 52
 }
Please login to merge, or discard this patch.
strategies/validation/EE_Min_Length_Validation_Strategy.strategy.php 2 patches
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -12,34 +12,34 @@
 block discarded – undo
12 12
 class EE_Min_Length_Validation_Strategy extends EE_Validation_Strategy_Base
13 13
 {
14 14
 
15
-    protected $_min_length;
15
+	protected $_min_length;
16 16
 
17
-    public function __construct($validation_error_message = null, $min_length = 0)
18
-    {
19
-        $this->_min_length = $min_length;
20
-        parent::__construct($validation_error_message);
21
-    }
17
+	public function __construct($validation_error_message = null, $min_length = 0)
18
+	{
19
+		$this->_min_length = $min_length;
20
+		parent::__construct($validation_error_message);
21
+	}
22 22
 
23
-    /**
24
-     * @param $normalized_value
25
-     */
26
-    public function validate($normalized_value)
27
-    {
28
-        if (
29
-            $this->_min_length > 0 &&
30
-                $normalized_value &&
31
-                is_string($normalized_value) &&
32
-                strlen($normalized_value) < $this->_min_length
33
-        ) {
34
-            throw new EE_Validation_Error($this->get_validation_error_message(), 'minlength');
35
-        }
36
-    }
23
+	/**
24
+	 * @param $normalized_value
25
+	 */
26
+	public function validate($normalized_value)
27
+	{
28
+		if (
29
+			$this->_min_length > 0 &&
30
+				$normalized_value &&
31
+				is_string($normalized_value) &&
32
+				strlen($normalized_value) < $this->_min_length
33
+		) {
34
+			throw new EE_Validation_Error($this->get_validation_error_message(), 'minlength');
35
+		}
36
+	}
37 37
 
38
-    /**
39
-     * @return array
40
-     */
41
-    public function get_jquery_validation_rule_array()
42
-    {
43
-        return array( 'minlength' => $this->_min_length, 'messages' => array( 'minlength' => $this->get_validation_error_message() ) );
44
-    }
38
+	/**
39
+	 * @return array
40
+	 */
41
+	public function get_jquery_validation_rule_array()
42
+	{
43
+		return array( 'minlength' => $this->_min_length, 'messages' => array( 'minlength' => $this->get_validation_error_message() ) );
44
+	}
45 45
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -40,6 +40,6 @@
 block discarded – undo
40 40
      */
41 41
     public function get_jquery_validation_rule_array()
42 42
     {
43
-        return array( 'minlength' => $this->_min_length, 'messages' => array( 'minlength' => $this->get_validation_error_message() ) );
43
+        return array('minlength' => $this->_min_length, 'messages' => array('minlength' => $this->get_validation_error_message()));
44 44
     }
45 45
 }
Please login to merge, or discard this patch.
strategies/validation/EE_Text_Validation_Strategy.strategy.php 2 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -11,53 +11,53 @@
 block discarded – undo
11 11
 class EE_Text_Validation_Strategy extends EE_Validation_Strategy_Base
12 12
 {
13 13
 
14
-    protected $_regex = null;
15
-    /**
16
-     *
17
-     * @param string $validation_error_message
18
-     * @param string $regex a PHP regex; the javascript regex will be derived from this
19
-     */
20
-    public function __construct($validation_error_message = null, $regex = null)
21
-    {
22
-        $this->_regex = $regex;
23
-        parent::__construct($validation_error_message);
24
-    }
14
+	protected $_regex = null;
15
+	/**
16
+	 *
17
+	 * @param string $validation_error_message
18
+	 * @param string $regex a PHP regex; the javascript regex will be derived from this
19
+	 */
20
+	public function __construct($validation_error_message = null, $regex = null)
21
+	{
22
+		$this->_regex = $regex;
23
+		parent::__construct($validation_error_message);
24
+	}
25 25
 
26
-    /**
27
-     * @param $normalized_value
28
-     */
29
-    public function validate($normalized_value)
30
-    {
31
-        $string_normalized_value = (string) $normalized_value;
32
-        if ($this->_regex &&  $string_normalized_value) {
33
-            if (! preg_match($this->_regex, $string_normalized_value)) {
34
-                throw new EE_Validation_Error($this->get_validation_error_message(), 'regex');
35
-            }
36
-        }
37
-    }
26
+	/**
27
+	 * @param $normalized_value
28
+	 */
29
+	public function validate($normalized_value)
30
+	{
31
+		$string_normalized_value = (string) $normalized_value;
32
+		if ($this->_regex &&  $string_normalized_value) {
33
+			if (! preg_match($this->_regex, $string_normalized_value)) {
34
+				throw new EE_Validation_Error($this->get_validation_error_message(), 'regex');
35
+			}
36
+		}
37
+	}
38 38
 
39
-    /**
40
-     * @return array
41
-     */
42
-    public function get_jquery_validation_rule_array()
43
-    {
44
-        if ($this->_regex !== null) {
45
-            return array( 'regex' => $this->regex_js(), 'messages' => array( 'regex' => $this->get_validation_error_message() ) );
46
-        } else {
47
-            return array();
48
-        }
49
-    }
39
+	/**
40
+	 * @return array
41
+	 */
42
+	public function get_jquery_validation_rule_array()
43
+	{
44
+		if ($this->_regex !== null) {
45
+			return array( 'regex' => $this->regex_js(), 'messages' => array( 'regex' => $this->get_validation_error_message() ) );
46
+		} else {
47
+			return array();
48
+		}
49
+	}
50 50
 
51 51
 /**
52 52
  * Translates a PHP regex into a javscript regex (eg, PHP needs separate delimieters, whereas
53 53
  * javscript does not
54 54
  * @return string
55 55
  */
56
-    public function regex_js()
57
-    {
58
-        // first character must be the delimiter
59
-        $delimeter = $this->_regex[0];
60
-        $last_occurence_of_delimieter = strrpos($this->_regex, $delimeter);
61
-        return substr($this->_regex, 1, $last_occurence_of_delimieter - 1);
62
-    }
56
+	public function regex_js()
57
+	{
58
+		// first character must be the delimiter
59
+		$delimeter = $this->_regex[0];
60
+		$last_occurence_of_delimieter = strrpos($this->_regex, $delimeter);
61
+		return substr($this->_regex, 1, $last_occurence_of_delimieter - 1);
62
+	}
63 63
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
     public function validate($normalized_value)
30 30
     {
31 31
         $string_normalized_value = (string) $normalized_value;
32
-        if ($this->_regex &&  $string_normalized_value) {
33
-            if (! preg_match($this->_regex, $string_normalized_value)) {
32
+        if ($this->_regex && $string_normalized_value) {
33
+            if ( ! preg_match($this->_regex, $string_normalized_value)) {
34 34
                 throw new EE_Validation_Error($this->get_validation_error_message(), 'regex');
35 35
             }
36 36
         }
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
     public function get_jquery_validation_rule_array()
43 43
     {
44 44
         if ($this->_regex !== null) {
45
-            return array( 'regex' => $this->regex_js(), 'messages' => array( 'regex' => $this->get_validation_error_message() ) );
45
+            return array('regex' => $this->regex_js(), 'messages' => array('regex' => $this->get_validation_error_message()));
46 46
         } else {
47 47
             return array();
48 48
         }
Please login to merge, or discard this patch.
core/libraries/form_sections/form_handlers/FormHandler.php 2 patches
Indentation   +639 added lines, -639 removed lines patch added patch discarded remove patch
@@ -29,643 +29,643 @@
 block discarded – undo
29 29
 abstract class FormHandler implements FormHandlerInterface
30 30
 {
31 31
 
32
-    /**
33
-     * will add opening and closing HTML form tags as well as a submit button
34
-     */
35
-    const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit';
36
-
37
-    /**
38
-     * will add opening and closing HTML form tags but NOT a submit button
39
-     */
40
-    const ADD_FORM_TAGS_ONLY = 'add_form_tags_only';
41
-
42
-    /**
43
-     * will NOT add opening and closing HTML form tags but will add a submit button
44
-     */
45
-    const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only';
46
-
47
-    /**
48
-     * will NOT add opening and closing HTML form tags NOR a submit button
49
-     */
50
-    const DO_NOT_SETUP_FORM = 'do_not_setup_form';
51
-
52
-    /**
53
-     * if set to false, then this form has no displayable content,
54
-     * and will only be used for processing data sent passed via GET or POST
55
-     * defaults to true ( ie: form has displayable content )
56
-     *
57
-     * @var boolean $displayable
58
-     */
59
-    private $displayable = true;
60
-
61
-    /**
62
-     * @var string $form_name
63
-     */
64
-    private $form_name;
65
-
66
-    /**
67
-     * @var string $admin_name
68
-     */
69
-    private $admin_name;
70
-
71
-    /**
72
-     * @var string $slug
73
-     */
74
-    private $slug;
75
-
76
-    /**
77
-     * @var string $submit_btn_text
78
-     */
79
-    private $submit_btn_text;
80
-
81
-    /**
82
-     * @var string $form_action
83
-     */
84
-    private $form_action;
85
-
86
-    /**
87
-     * form params in key value pairs
88
-     * can be added to form action URL or as hidden inputs
89
-     *
90
-     * @var array $form_args
91
-     */
92
-    private $form_args = array();
93
-
94
-    /**
95
-     * value of one of the string constant above
96
-     *
97
-     * @var string $form_config
98
-     */
99
-    private $form_config;
100
-
101
-    /**
102
-     * whether or not the form was determined to be invalid
103
-     *
104
-     * @var boolean $form_has_errors
105
-     */
106
-    private $form_has_errors;
107
-
108
-    /**
109
-     * the absolute top level form section being used on the page
110
-     *
111
-     * @var EE_Form_Section_Proper $form
112
-     */
113
-    private $form;
114
-
115
-    /**
116
-     * @var EE_Registry $registry
117
-     */
118
-    protected $registry;
119
-
120
-    // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd
121
-    /**
122
-     * Form constructor.
123
-     *
124
-     * @param string      $form_name
125
-     * @param string      $admin_name
126
-     * @param string      $slug
127
-     * @param string      $form_action
128
-     * @param string      $form_config
129
-     * @param EE_Registry $registry
130
-     * @throws InvalidDataTypeException
131
-     * @throws DomainException
132
-     * @throws InvalidArgumentException
133
-     */
134
-    public function __construct(
135
-        $form_name,
136
-        $admin_name,
137
-        $slug,
138
-        $form_action = '',
139
-        $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
140
-        EE_Registry $registry
141
-    ) {
142
-        $this->setFormName($form_name);
143
-        $this->setAdminName($admin_name);
144
-        $this->setSlug($slug);
145
-        $this->setFormAction($form_action);
146
-        $this->setFormConfig($form_config);
147
-        $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso'));
148
-        $this->registry = $registry;
149
-    }
150
-
151
-
152
-    /**
153
-     * @return array
154
-     */
155
-    public static function getFormConfigConstants()
156
-    {
157
-        return array(
158
-            FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
159
-            FormHandler::ADD_FORM_TAGS_ONLY,
160
-            FormHandler::ADD_FORM_SUBMIT_ONLY,
161
-            FormHandler::DO_NOT_SETUP_FORM,
162
-        );
163
-    }
164
-
165
-
166
-    /**
167
-     * @param bool $for_display
168
-     * @return EE_Form_Section_Proper
169
-     * @throws EE_Error
170
-     * @throws LogicException
171
-     */
172
-    public function form($for_display = false)
173
-    {
174
-        if (! $this->formIsValid()) {
175
-            return null;
176
-        }
177
-        if ($for_display) {
178
-            $form_config = $this->formConfig();
179
-            if (
180
-                $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
181
-                || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY
182
-            ) {
183
-                $this->appendSubmitButton();
184
-                $this->clearFormButtonFloats();
185
-            }
186
-        }
187
-        return $this->form;
188
-    }
189
-
190
-
191
-    /**
192
-     * @return boolean
193
-     * @throws LogicException
194
-     */
195
-    public function formIsValid()
196
-    {
197
-        if ($this->form instanceof EE_Form_Section_Proper) {
198
-            return true;
199
-        }
200
-        $form = apply_filters(
201
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object',
202
-            $this->generate(),
203
-            $this
204
-        );
205
-        if ($this->verifyForm($form)) {
206
-            $this->setForm($form);
207
-        }
208
-        return true;
209
-    }
210
-
211
-
212
-    /**
213
-     * @param EE_Form_Section_Proper|null $form
214
-     * @return bool
215
-     * @throws LogicException
216
-     */
217
-    public function verifyForm(EE_Form_Section_Proper $form = null)
218
-    {
219
-        $form = $form !== null ? $form : $this->form;
220
-        if ($form instanceof EE_Form_Section_Proper) {
221
-            return true;
222
-        }
223
-        throw new LogicException(
224
-            sprintf(
225
-                esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'),
226
-                $this->form_name,
227
-                var_export($form, true)
228
-            )
229
-        );
230
-    }
231
-
232
-
233
-    /**
234
-     * @param EE_Form_Section_Proper $form
235
-     */
236
-    public function setForm(EE_Form_Section_Proper $form)
237
-    {
238
-        $this->form = $form;
239
-    }
240
-
241
-
242
-    /**
243
-     * @return boolean
244
-     */
245
-    public function displayable()
246
-    {
247
-        return $this->displayable;
248
-    }
249
-
250
-
251
-    /**
252
-     * @param boolean $displayable
253
-     */
254
-    public function setDisplayable($displayable = false)
255
-    {
256
-        $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN);
257
-    }
258
-
259
-
260
-    /**
261
-     * a public name for the form that can be displayed on the frontend of a site
262
-     *
263
-     * @return string
264
-     */
265
-    public function formName()
266
-    {
267
-        return $this->form_name;
268
-    }
269
-
270
-
271
-    /**
272
-     * @param string $form_name
273
-     * @throws InvalidDataTypeException
274
-     */
275
-    public function setFormName($form_name)
276
-    {
277
-        if (! is_string($form_name)) {
278
-            throw new InvalidDataTypeException('$form_name', $form_name, 'string');
279
-        }
280
-        $this->form_name = $form_name;
281
-    }
282
-
283
-
284
-    /**
285
-     * a public name for the form that can be displayed, but only in the admin
286
-     *
287
-     * @return string
288
-     */
289
-    public function adminName()
290
-    {
291
-        return $this->admin_name;
292
-    }
293
-
294
-
295
-    /**
296
-     * @param string $admin_name
297
-     * @throws InvalidDataTypeException
298
-     */
299
-    public function setAdminName($admin_name)
300
-    {
301
-        if (! is_string($admin_name)) {
302
-            throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
303
-        }
304
-        $this->admin_name = $admin_name;
305
-    }
306
-
307
-
308
-    /**
309
-     * a URL friendly string that can be used for identifying the form
310
-     *
311
-     * @return string
312
-     */
313
-    public function slug()
314
-    {
315
-        return $this->slug;
316
-    }
317
-
318
-
319
-    /**
320
-     * @param string $slug
321
-     * @throws InvalidDataTypeException
322
-     */
323
-    public function setSlug($slug)
324
-    {
325
-        if (! is_string($slug)) {
326
-            throw new InvalidDataTypeException('$slug', $slug, 'string');
327
-        }
328
-        $this->slug = $slug;
329
-    }
330
-
331
-
332
-    /**
333
-     * @return string
334
-     */
335
-    public function submitBtnText()
336
-    {
337
-        return $this->submit_btn_text;
338
-    }
339
-
340
-
341
-    /**
342
-     * @param string $submit_btn_text
343
-     * @throws InvalidDataTypeException
344
-     * @throws InvalidArgumentException
345
-     */
346
-    public function setSubmitBtnText($submit_btn_text)
347
-    {
348
-        if (! is_string($submit_btn_text)) {
349
-            throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
350
-        }
351
-        if (empty($submit_btn_text)) {
352
-            throw new InvalidArgumentException(
353
-                esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso')
354
-            );
355
-        }
356
-        $this->submit_btn_text = $submit_btn_text;
357
-    }
358
-
359
-
360
-    /**
361
-     * @return string
362
-     */
363
-    public function formAction()
364
-    {
365
-        return ! empty($this->form_args)
366
-            ? add_query_arg($this->form_args, $this->form_action)
367
-            : $this->form_action;
368
-    }
369
-
370
-
371
-    /**
372
-     * @param string $form_action
373
-     * @throws InvalidDataTypeException
374
-     */
375
-    public function setFormAction($form_action)
376
-    {
377
-        if (! is_string($form_action)) {
378
-            throw new InvalidDataTypeException('$form_action', $form_action, 'string');
379
-        }
380
-        $this->form_action = $form_action;
381
-    }
382
-
383
-
384
-    /**
385
-     * @param array $form_args
386
-     * @throws InvalidDataTypeException
387
-     * @throws InvalidArgumentException
388
-     */
389
-    public function addFormActionArgs($form_args = array())
390
-    {
391
-        if (is_object($form_args)) {
392
-            throw new InvalidDataTypeException(
393
-                '$form_args',
394
-                $form_args,
395
-                'anything other than an object was expected.'
396
-            );
397
-        }
398
-        if (empty($form_args)) {
399
-            throw new InvalidArgumentException(
400
-                esc_html__('The redirect arguments can not be an empty array.', 'event_espresso')
401
-            );
402
-        }
403
-        $this->form_args = array_merge($this->form_args, $form_args);
404
-    }
405
-
406
-
407
-    /**
408
-     * @return string
409
-     */
410
-    public function formConfig()
411
-    {
412
-        return $this->form_config;
413
-    }
414
-
415
-
416
-    /**
417
-     * @param string $form_config
418
-     * @throws DomainException
419
-     */
420
-    public function setFormConfig($form_config)
421
-    {
422
-        if (
423
-            ! in_array(
424
-                $form_config,
425
-                array(
426
-                FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
427
-                FormHandler::ADD_FORM_TAGS_ONLY,
428
-                FormHandler::ADD_FORM_SUBMIT_ONLY,
429
-                FormHandler::DO_NOT_SETUP_FORM,
430
-                ),
431
-                true
432
-            )
433
-        ) {
434
-            throw new DomainException(
435
-                sprintf(
436
-                    esc_html__(
437
-                        '"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form',
438
-                        'event_espresso'
439
-                    ),
440
-                    $form_config
441
-                )
442
-            );
443
-        }
444
-        $this->form_config = $form_config;
445
-    }
446
-
447
-
448
-    /**
449
-     * called after the form is instantiated
450
-     * and used for performing any logic that needs to occur early
451
-     * before any of the other methods are called.
452
-     * returns true if everything is ok to proceed,
453
-     * and false if no further form logic should be implemented
454
-     *
455
-     * @return boolean
456
-     */
457
-    public function initialize()
458
-    {
459
-        $this->form_has_errors = EE_Error::has_error(true);
460
-        return true;
461
-    }
462
-
463
-
464
-    /**
465
-     * used for setting up css and js
466
-     *
467
-     * @return void
468
-     * @throws LogicException
469
-     * @throws EE_Error
470
-     */
471
-    public function enqueueStylesAndScripts()
472
-    {
473
-        $this->form()->enqueue_js();
474
-    }
475
-
476
-
477
-    /**
478
-     * creates and returns the actual form
479
-     *
480
-     * @return EE_Form_Section_Proper
481
-     */
482
-    abstract public function generate();
483
-
484
-
485
-    /**
486
-     * creates and returns an EE_Submit_Input labeled "Submit"
487
-     *
488
-     * @param string $text
489
-     * @return EE_Submit_Input
490
-     */
491
-    public function generateSubmitButton($text = '')
492
-    {
493
-        $text = ! empty($text) ? $text : $this->submitBtnText();
494
-        return new EE_Submit_Input(
495
-            array(
496
-                'html_name'             => 'ee-form-submit-' . $this->slug(),
497
-                'html_id'               => 'ee-form-submit-' . $this->slug(),
498
-                'html_class'            => 'ee-form-submit',
499
-                'html_label'            => '&nbsp;',
500
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
501
-                'default'               => $text,
502
-            )
503
-        );
504
-    }
505
-
506
-
507
-    /**
508
-     * calls generateSubmitButton() and appends it onto the form along with a float clearing div
509
-     *
510
-     * @param string $text
511
-     * @return void
512
-     * @throws EE_Error
513
-     */
514
-    public function appendSubmitButton($text = '')
515
-    {
516
-        if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
517
-            return;
518
-        }
519
-        $this->form->add_subsections(
520
-            array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
521
-            null,
522
-            false
523
-        );
524
-    }
525
-
526
-
527
-    /**
528
-     * creates and returns an EE_Submit_Input labeled "Cancel"
529
-     *
530
-     * @param string $text
531
-     * @return EE_Submit_Input
532
-     */
533
-    public function generateCancelButton($text = '')
534
-    {
535
-        $cancel_button = new EE_Submit_Input(
536
-            array(
537
-                'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
538
-                'html_id'               => 'ee-cancel-form-' . $this->slug(),
539
-                'html_class'            => 'ee-cancel-form',
540
-                'html_label'            => '&nbsp;',
541
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
542
-                'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
543
-            )
544
-        );
545
-        $cancel_button->set_button_css_attributes(false);
546
-        return $cancel_button;
547
-    }
548
-
549
-
550
-    /**
551
-     * appends a float clearing div onto end of form
552
-     *
553
-     * @return void
554
-     * @throws EE_Error
555
-     */
556
-    public function clearFormButtonFloats()
557
-    {
558
-        $this->form->add_subsections(
559
-            array(
560
-                'clear-submit-btn-float' => new EE_Form_Section_HTML(
561
-                    EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
562
-                ),
563
-            ),
564
-            null,
565
-            false
566
-        );
567
-    }
568
-
569
-
570
-    /**
571
-     * takes the generated form and displays it along with ony other non-form HTML that may be required
572
-     * returns a string of HTML that can be directly echoed in a template
573
-     *
574
-     * @return string
575
-     * @throws \InvalidArgumentException
576
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
577
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
578
-     * @throws LogicException
579
-     * @throws EE_Error
580
-     */
581
-    public function display()
582
-    {
583
-        $form_html = apply_filters(
584
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
585
-            ''
586
-        );
587
-        $form_config = $this->formConfig();
588
-        if (
589
-            $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
590
-            || $form_config === FormHandler::ADD_FORM_TAGS_ONLY
591
-        ) {
592
-            $additional_props = $this->requiresMultipartEnctype()
593
-                ? 'enctype="multipart/form-data"'
594
-                : '';
595
-            $form_html .= $this->form()->form_open(
596
-                $this->formAction(),
597
-                'POST',
598
-                $additional_props
599
-            );
600
-        }
601
-        $form_html .= $this->form(true)->get_html();
602
-        if (
603
-            $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
604
-            || $form_config === FormHandler::ADD_FORM_TAGS_ONLY
605
-        ) {
606
-            $form_html .= $this->form()->form_close();
607
-        }
608
-        $form_html .= apply_filters(
609
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form',
610
-            ''
611
-        );
612
-        return $form_html;
613
-    }
614
-
615
-    /**
616
-     * Determines if this form needs "enctype='multipart/form-data'" or not.
617
-     * @since 4.9.80.p
618
-     * @return bool
619
-     * @throws EE_Error
620
-     */
621
-    public function requiresMultipartEnctype()
622
-    {
623
-        foreach ($this->form()->inputs_in_subsections() as $input) {
624
-            if ($input instanceof EE_File_Input) {
625
-                return true;
626
-            }
627
-        }
628
-        return false;
629
-    }
630
-
631
-
632
-    /**
633
-     * handles processing the form submission
634
-     * returns true or false depending on whether the form was processed successfully or not
635
-     *
636
-     * @param array $submitted_form_data
637
-     * @return array
638
-     * @throws \InvalidArgumentException
639
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
640
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
641
-     * @throws EE_Error
642
-     * @throws LogicException
643
-     * @throws InvalidFormSubmissionException
644
-     */
645
-    public function process($submitted_form_data = array())
646
-    {
647
-        if (! $this->form()->was_submitted($submitted_form_data)) {
648
-            throw new InvalidFormSubmissionException($this->form_name);
649
-        }
650
-        $this->form(true)->receive_form_submission($submitted_form_data);
651
-        if (! $this->form()->is_valid()) {
652
-            throw new InvalidFormSubmissionException(
653
-                $this->form_name,
654
-                sprintf(
655
-                    esc_html__(
656
-                        'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s',
657
-                        'event_espresso'
658
-                    ),
659
-                    $this->form_name,
660
-                    '<br />',
661
-                    implode('<br />', $this->form()->get_validation_errors_accumulated())
662
-                )
663
-            );
664
-        }
665
-        return apply_filters(
666
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data',
667
-            $this->form()->valid_data(),
668
-            $this
669
-        );
670
-    }
32
+	/**
33
+	 * will add opening and closing HTML form tags as well as a submit button
34
+	 */
35
+	const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit';
36
+
37
+	/**
38
+	 * will add opening and closing HTML form tags but NOT a submit button
39
+	 */
40
+	const ADD_FORM_TAGS_ONLY = 'add_form_tags_only';
41
+
42
+	/**
43
+	 * will NOT add opening and closing HTML form tags but will add a submit button
44
+	 */
45
+	const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only';
46
+
47
+	/**
48
+	 * will NOT add opening and closing HTML form tags NOR a submit button
49
+	 */
50
+	const DO_NOT_SETUP_FORM = 'do_not_setup_form';
51
+
52
+	/**
53
+	 * if set to false, then this form has no displayable content,
54
+	 * and will only be used for processing data sent passed via GET or POST
55
+	 * defaults to true ( ie: form has displayable content )
56
+	 *
57
+	 * @var boolean $displayable
58
+	 */
59
+	private $displayable = true;
60
+
61
+	/**
62
+	 * @var string $form_name
63
+	 */
64
+	private $form_name;
65
+
66
+	/**
67
+	 * @var string $admin_name
68
+	 */
69
+	private $admin_name;
70
+
71
+	/**
72
+	 * @var string $slug
73
+	 */
74
+	private $slug;
75
+
76
+	/**
77
+	 * @var string $submit_btn_text
78
+	 */
79
+	private $submit_btn_text;
80
+
81
+	/**
82
+	 * @var string $form_action
83
+	 */
84
+	private $form_action;
85
+
86
+	/**
87
+	 * form params in key value pairs
88
+	 * can be added to form action URL or as hidden inputs
89
+	 *
90
+	 * @var array $form_args
91
+	 */
92
+	private $form_args = array();
93
+
94
+	/**
95
+	 * value of one of the string constant above
96
+	 *
97
+	 * @var string $form_config
98
+	 */
99
+	private $form_config;
100
+
101
+	/**
102
+	 * whether or not the form was determined to be invalid
103
+	 *
104
+	 * @var boolean $form_has_errors
105
+	 */
106
+	private $form_has_errors;
107
+
108
+	/**
109
+	 * the absolute top level form section being used on the page
110
+	 *
111
+	 * @var EE_Form_Section_Proper $form
112
+	 */
113
+	private $form;
114
+
115
+	/**
116
+	 * @var EE_Registry $registry
117
+	 */
118
+	protected $registry;
119
+
120
+	// phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd
121
+	/**
122
+	 * Form constructor.
123
+	 *
124
+	 * @param string      $form_name
125
+	 * @param string      $admin_name
126
+	 * @param string      $slug
127
+	 * @param string      $form_action
128
+	 * @param string      $form_config
129
+	 * @param EE_Registry $registry
130
+	 * @throws InvalidDataTypeException
131
+	 * @throws DomainException
132
+	 * @throws InvalidArgumentException
133
+	 */
134
+	public function __construct(
135
+		$form_name,
136
+		$admin_name,
137
+		$slug,
138
+		$form_action = '',
139
+		$form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
140
+		EE_Registry $registry
141
+	) {
142
+		$this->setFormName($form_name);
143
+		$this->setAdminName($admin_name);
144
+		$this->setSlug($slug);
145
+		$this->setFormAction($form_action);
146
+		$this->setFormConfig($form_config);
147
+		$this->setSubmitBtnText(esc_html__('Submit', 'event_espresso'));
148
+		$this->registry = $registry;
149
+	}
150
+
151
+
152
+	/**
153
+	 * @return array
154
+	 */
155
+	public static function getFormConfigConstants()
156
+	{
157
+		return array(
158
+			FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
159
+			FormHandler::ADD_FORM_TAGS_ONLY,
160
+			FormHandler::ADD_FORM_SUBMIT_ONLY,
161
+			FormHandler::DO_NOT_SETUP_FORM,
162
+		);
163
+	}
164
+
165
+
166
+	/**
167
+	 * @param bool $for_display
168
+	 * @return EE_Form_Section_Proper
169
+	 * @throws EE_Error
170
+	 * @throws LogicException
171
+	 */
172
+	public function form($for_display = false)
173
+	{
174
+		if (! $this->formIsValid()) {
175
+			return null;
176
+		}
177
+		if ($for_display) {
178
+			$form_config = $this->formConfig();
179
+			if (
180
+				$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
181
+				|| $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY
182
+			) {
183
+				$this->appendSubmitButton();
184
+				$this->clearFormButtonFloats();
185
+			}
186
+		}
187
+		return $this->form;
188
+	}
189
+
190
+
191
+	/**
192
+	 * @return boolean
193
+	 * @throws LogicException
194
+	 */
195
+	public function formIsValid()
196
+	{
197
+		if ($this->form instanceof EE_Form_Section_Proper) {
198
+			return true;
199
+		}
200
+		$form = apply_filters(
201
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object',
202
+			$this->generate(),
203
+			$this
204
+		);
205
+		if ($this->verifyForm($form)) {
206
+			$this->setForm($form);
207
+		}
208
+		return true;
209
+	}
210
+
211
+
212
+	/**
213
+	 * @param EE_Form_Section_Proper|null $form
214
+	 * @return bool
215
+	 * @throws LogicException
216
+	 */
217
+	public function verifyForm(EE_Form_Section_Proper $form = null)
218
+	{
219
+		$form = $form !== null ? $form : $this->form;
220
+		if ($form instanceof EE_Form_Section_Proper) {
221
+			return true;
222
+		}
223
+		throw new LogicException(
224
+			sprintf(
225
+				esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'),
226
+				$this->form_name,
227
+				var_export($form, true)
228
+			)
229
+		);
230
+	}
231
+
232
+
233
+	/**
234
+	 * @param EE_Form_Section_Proper $form
235
+	 */
236
+	public function setForm(EE_Form_Section_Proper $form)
237
+	{
238
+		$this->form = $form;
239
+	}
240
+
241
+
242
+	/**
243
+	 * @return boolean
244
+	 */
245
+	public function displayable()
246
+	{
247
+		return $this->displayable;
248
+	}
249
+
250
+
251
+	/**
252
+	 * @param boolean $displayable
253
+	 */
254
+	public function setDisplayable($displayable = false)
255
+	{
256
+		$this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN);
257
+	}
258
+
259
+
260
+	/**
261
+	 * a public name for the form that can be displayed on the frontend of a site
262
+	 *
263
+	 * @return string
264
+	 */
265
+	public function formName()
266
+	{
267
+		return $this->form_name;
268
+	}
269
+
270
+
271
+	/**
272
+	 * @param string $form_name
273
+	 * @throws InvalidDataTypeException
274
+	 */
275
+	public function setFormName($form_name)
276
+	{
277
+		if (! is_string($form_name)) {
278
+			throw new InvalidDataTypeException('$form_name', $form_name, 'string');
279
+		}
280
+		$this->form_name = $form_name;
281
+	}
282
+
283
+
284
+	/**
285
+	 * a public name for the form that can be displayed, but only in the admin
286
+	 *
287
+	 * @return string
288
+	 */
289
+	public function adminName()
290
+	{
291
+		return $this->admin_name;
292
+	}
293
+
294
+
295
+	/**
296
+	 * @param string $admin_name
297
+	 * @throws InvalidDataTypeException
298
+	 */
299
+	public function setAdminName($admin_name)
300
+	{
301
+		if (! is_string($admin_name)) {
302
+			throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
303
+		}
304
+		$this->admin_name = $admin_name;
305
+	}
306
+
307
+
308
+	/**
309
+	 * a URL friendly string that can be used for identifying the form
310
+	 *
311
+	 * @return string
312
+	 */
313
+	public function slug()
314
+	{
315
+		return $this->slug;
316
+	}
317
+
318
+
319
+	/**
320
+	 * @param string $slug
321
+	 * @throws InvalidDataTypeException
322
+	 */
323
+	public function setSlug($slug)
324
+	{
325
+		if (! is_string($slug)) {
326
+			throw new InvalidDataTypeException('$slug', $slug, 'string');
327
+		}
328
+		$this->slug = $slug;
329
+	}
330
+
331
+
332
+	/**
333
+	 * @return string
334
+	 */
335
+	public function submitBtnText()
336
+	{
337
+		return $this->submit_btn_text;
338
+	}
339
+
340
+
341
+	/**
342
+	 * @param string $submit_btn_text
343
+	 * @throws InvalidDataTypeException
344
+	 * @throws InvalidArgumentException
345
+	 */
346
+	public function setSubmitBtnText($submit_btn_text)
347
+	{
348
+		if (! is_string($submit_btn_text)) {
349
+			throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
350
+		}
351
+		if (empty($submit_btn_text)) {
352
+			throw new InvalidArgumentException(
353
+				esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso')
354
+			);
355
+		}
356
+		$this->submit_btn_text = $submit_btn_text;
357
+	}
358
+
359
+
360
+	/**
361
+	 * @return string
362
+	 */
363
+	public function formAction()
364
+	{
365
+		return ! empty($this->form_args)
366
+			? add_query_arg($this->form_args, $this->form_action)
367
+			: $this->form_action;
368
+	}
369
+
370
+
371
+	/**
372
+	 * @param string $form_action
373
+	 * @throws InvalidDataTypeException
374
+	 */
375
+	public function setFormAction($form_action)
376
+	{
377
+		if (! is_string($form_action)) {
378
+			throw new InvalidDataTypeException('$form_action', $form_action, 'string');
379
+		}
380
+		$this->form_action = $form_action;
381
+	}
382
+
383
+
384
+	/**
385
+	 * @param array $form_args
386
+	 * @throws InvalidDataTypeException
387
+	 * @throws InvalidArgumentException
388
+	 */
389
+	public function addFormActionArgs($form_args = array())
390
+	{
391
+		if (is_object($form_args)) {
392
+			throw new InvalidDataTypeException(
393
+				'$form_args',
394
+				$form_args,
395
+				'anything other than an object was expected.'
396
+			);
397
+		}
398
+		if (empty($form_args)) {
399
+			throw new InvalidArgumentException(
400
+				esc_html__('The redirect arguments can not be an empty array.', 'event_espresso')
401
+			);
402
+		}
403
+		$this->form_args = array_merge($this->form_args, $form_args);
404
+	}
405
+
406
+
407
+	/**
408
+	 * @return string
409
+	 */
410
+	public function formConfig()
411
+	{
412
+		return $this->form_config;
413
+	}
414
+
415
+
416
+	/**
417
+	 * @param string $form_config
418
+	 * @throws DomainException
419
+	 */
420
+	public function setFormConfig($form_config)
421
+	{
422
+		if (
423
+			! in_array(
424
+				$form_config,
425
+				array(
426
+				FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
427
+				FormHandler::ADD_FORM_TAGS_ONLY,
428
+				FormHandler::ADD_FORM_SUBMIT_ONLY,
429
+				FormHandler::DO_NOT_SETUP_FORM,
430
+				),
431
+				true
432
+			)
433
+		) {
434
+			throw new DomainException(
435
+				sprintf(
436
+					esc_html__(
437
+						'"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form',
438
+						'event_espresso'
439
+					),
440
+					$form_config
441
+				)
442
+			);
443
+		}
444
+		$this->form_config = $form_config;
445
+	}
446
+
447
+
448
+	/**
449
+	 * called after the form is instantiated
450
+	 * and used for performing any logic that needs to occur early
451
+	 * before any of the other methods are called.
452
+	 * returns true if everything is ok to proceed,
453
+	 * and false if no further form logic should be implemented
454
+	 *
455
+	 * @return boolean
456
+	 */
457
+	public function initialize()
458
+	{
459
+		$this->form_has_errors = EE_Error::has_error(true);
460
+		return true;
461
+	}
462
+
463
+
464
+	/**
465
+	 * used for setting up css and js
466
+	 *
467
+	 * @return void
468
+	 * @throws LogicException
469
+	 * @throws EE_Error
470
+	 */
471
+	public function enqueueStylesAndScripts()
472
+	{
473
+		$this->form()->enqueue_js();
474
+	}
475
+
476
+
477
+	/**
478
+	 * creates and returns the actual form
479
+	 *
480
+	 * @return EE_Form_Section_Proper
481
+	 */
482
+	abstract public function generate();
483
+
484
+
485
+	/**
486
+	 * creates and returns an EE_Submit_Input labeled "Submit"
487
+	 *
488
+	 * @param string $text
489
+	 * @return EE_Submit_Input
490
+	 */
491
+	public function generateSubmitButton($text = '')
492
+	{
493
+		$text = ! empty($text) ? $text : $this->submitBtnText();
494
+		return new EE_Submit_Input(
495
+			array(
496
+				'html_name'             => 'ee-form-submit-' . $this->slug(),
497
+				'html_id'               => 'ee-form-submit-' . $this->slug(),
498
+				'html_class'            => 'ee-form-submit',
499
+				'html_label'            => '&nbsp;',
500
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
501
+				'default'               => $text,
502
+			)
503
+		);
504
+	}
505
+
506
+
507
+	/**
508
+	 * calls generateSubmitButton() and appends it onto the form along with a float clearing div
509
+	 *
510
+	 * @param string $text
511
+	 * @return void
512
+	 * @throws EE_Error
513
+	 */
514
+	public function appendSubmitButton($text = '')
515
+	{
516
+		if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
517
+			return;
518
+		}
519
+		$this->form->add_subsections(
520
+			array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
521
+			null,
522
+			false
523
+		);
524
+	}
525
+
526
+
527
+	/**
528
+	 * creates and returns an EE_Submit_Input labeled "Cancel"
529
+	 *
530
+	 * @param string $text
531
+	 * @return EE_Submit_Input
532
+	 */
533
+	public function generateCancelButton($text = '')
534
+	{
535
+		$cancel_button = new EE_Submit_Input(
536
+			array(
537
+				'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
538
+				'html_id'               => 'ee-cancel-form-' . $this->slug(),
539
+				'html_class'            => 'ee-cancel-form',
540
+				'html_label'            => '&nbsp;',
541
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
542
+				'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
543
+			)
544
+		);
545
+		$cancel_button->set_button_css_attributes(false);
546
+		return $cancel_button;
547
+	}
548
+
549
+
550
+	/**
551
+	 * appends a float clearing div onto end of form
552
+	 *
553
+	 * @return void
554
+	 * @throws EE_Error
555
+	 */
556
+	public function clearFormButtonFloats()
557
+	{
558
+		$this->form->add_subsections(
559
+			array(
560
+				'clear-submit-btn-float' => new EE_Form_Section_HTML(
561
+					EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
562
+				),
563
+			),
564
+			null,
565
+			false
566
+		);
567
+	}
568
+
569
+
570
+	/**
571
+	 * takes the generated form and displays it along with ony other non-form HTML that may be required
572
+	 * returns a string of HTML that can be directly echoed in a template
573
+	 *
574
+	 * @return string
575
+	 * @throws \InvalidArgumentException
576
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
577
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
578
+	 * @throws LogicException
579
+	 * @throws EE_Error
580
+	 */
581
+	public function display()
582
+	{
583
+		$form_html = apply_filters(
584
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
585
+			''
586
+		);
587
+		$form_config = $this->formConfig();
588
+		if (
589
+			$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
590
+			|| $form_config === FormHandler::ADD_FORM_TAGS_ONLY
591
+		) {
592
+			$additional_props = $this->requiresMultipartEnctype()
593
+				? 'enctype="multipart/form-data"'
594
+				: '';
595
+			$form_html .= $this->form()->form_open(
596
+				$this->formAction(),
597
+				'POST',
598
+				$additional_props
599
+			);
600
+		}
601
+		$form_html .= $this->form(true)->get_html();
602
+		if (
603
+			$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
604
+			|| $form_config === FormHandler::ADD_FORM_TAGS_ONLY
605
+		) {
606
+			$form_html .= $this->form()->form_close();
607
+		}
608
+		$form_html .= apply_filters(
609
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form',
610
+			''
611
+		);
612
+		return $form_html;
613
+	}
614
+
615
+	/**
616
+	 * Determines if this form needs "enctype='multipart/form-data'" or not.
617
+	 * @since 4.9.80.p
618
+	 * @return bool
619
+	 * @throws EE_Error
620
+	 */
621
+	public function requiresMultipartEnctype()
622
+	{
623
+		foreach ($this->form()->inputs_in_subsections() as $input) {
624
+			if ($input instanceof EE_File_Input) {
625
+				return true;
626
+			}
627
+		}
628
+		return false;
629
+	}
630
+
631
+
632
+	/**
633
+	 * handles processing the form submission
634
+	 * returns true or false depending on whether the form was processed successfully or not
635
+	 *
636
+	 * @param array $submitted_form_data
637
+	 * @return array
638
+	 * @throws \InvalidArgumentException
639
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
640
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
641
+	 * @throws EE_Error
642
+	 * @throws LogicException
643
+	 * @throws InvalidFormSubmissionException
644
+	 */
645
+	public function process($submitted_form_data = array())
646
+	{
647
+		if (! $this->form()->was_submitted($submitted_form_data)) {
648
+			throw new InvalidFormSubmissionException($this->form_name);
649
+		}
650
+		$this->form(true)->receive_form_submission($submitted_form_data);
651
+		if (! $this->form()->is_valid()) {
652
+			throw new InvalidFormSubmissionException(
653
+				$this->form_name,
654
+				sprintf(
655
+					esc_html__(
656
+						'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s',
657
+						'event_espresso'
658
+					),
659
+					$this->form_name,
660
+					'<br />',
661
+					implode('<br />', $this->form()->get_validation_errors_accumulated())
662
+				)
663
+			);
664
+		}
665
+		return apply_filters(
666
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data',
667
+			$this->form()->valid_data(),
668
+			$this
669
+		);
670
+	}
671 671
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
      */
172 172
     public function form($for_display = false)
173 173
     {
174
-        if (! $this->formIsValid()) {
174
+        if ( ! $this->formIsValid()) {
175 175
             return null;
176 176
         }
177 177
         if ($for_display) {
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
      */
275 275
     public function setFormName($form_name)
276 276
     {
277
-        if (! is_string($form_name)) {
277
+        if ( ! is_string($form_name)) {
278 278
             throw new InvalidDataTypeException('$form_name', $form_name, 'string');
279 279
         }
280 280
         $this->form_name = $form_name;
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
      */
299 299
     public function setAdminName($admin_name)
300 300
     {
301
-        if (! is_string($admin_name)) {
301
+        if ( ! is_string($admin_name)) {
302 302
             throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
303 303
         }
304 304
         $this->admin_name = $admin_name;
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
      */
323 323
     public function setSlug($slug)
324 324
     {
325
-        if (! is_string($slug)) {
325
+        if ( ! is_string($slug)) {
326 326
             throw new InvalidDataTypeException('$slug', $slug, 'string');
327 327
         }
328 328
         $this->slug = $slug;
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
      */
346 346
     public function setSubmitBtnText($submit_btn_text)
347 347
     {
348
-        if (! is_string($submit_btn_text)) {
348
+        if ( ! is_string($submit_btn_text)) {
349 349
             throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
350 350
         }
351 351
         if (empty($submit_btn_text)) {
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
      */
375 375
     public function setFormAction($form_action)
376 376
     {
377
-        if (! is_string($form_action)) {
377
+        if ( ! is_string($form_action)) {
378 378
             throw new InvalidDataTypeException('$form_action', $form_action, 'string');
379 379
         }
380 380
         $this->form_action = $form_action;
@@ -493,11 +493,11 @@  discard block
 block discarded – undo
493 493
         $text = ! empty($text) ? $text : $this->submitBtnText();
494 494
         return new EE_Submit_Input(
495 495
             array(
496
-                'html_name'             => 'ee-form-submit-' . $this->slug(),
497
-                'html_id'               => 'ee-form-submit-' . $this->slug(),
496
+                'html_name'             => 'ee-form-submit-'.$this->slug(),
497
+                'html_id'               => 'ee-form-submit-'.$this->slug(),
498 498
                 'html_class'            => 'ee-form-submit',
499 499
                 'html_label'            => '&nbsp;',
500
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
500
+                'other_html_attributes' => ' rel="'.$this->slug().'"',
501 501
                 'default'               => $text,
502 502
             )
503 503
         );
@@ -513,11 +513,11 @@  discard block
 block discarded – undo
513 513
      */
514 514
     public function appendSubmitButton($text = '')
515 515
     {
516
-        if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
516
+        if ($this->form->subsection_exists($this->slug().'-submit-btn')) {
517 517
             return;
518 518
         }
519 519
         $this->form->add_subsections(
520
-            array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
520
+            array($this->slug().'-submit-btn' => $this->generateSubmitButton($text)),
521 521
             null,
522 522
             false
523 523
         );
@@ -534,11 +534,11 @@  discard block
 block discarded – undo
534 534
     {
535 535
         $cancel_button = new EE_Submit_Input(
536 536
             array(
537
-                'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
538
-                'html_id'               => 'ee-cancel-form-' . $this->slug(),
537
+                'html_name'             => 'ee-form-submit-'.$this->slug(), // YES! Same name as submit !!!
538
+                'html_id'               => 'ee-cancel-form-'.$this->slug(),
539 539
                 'html_class'            => 'ee-cancel-form',
540 540
                 'html_label'            => '&nbsp;',
541
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
541
+                'other_html_attributes' => ' rel="'.$this->slug().'"',
542 542
                 'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
543 543
             )
544 544
         );
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
         $this->form->add_subsections(
559 559
             array(
560 560
                 'clear-submit-btn-float' => new EE_Form_Section_HTML(
561
-                    EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
561
+                    EEH_HTML::div('', '', 'clear-float').EEH_HTML::divx()
562 562
                 ),
563 563
             ),
564 564
             null,
@@ -644,11 +644,11 @@  discard block
 block discarded – undo
644 644
      */
645 645
     public function process($submitted_form_data = array())
646 646
     {
647
-        if (! $this->form()->was_submitted($submitted_form_data)) {
647
+        if ( ! $this->form()->was_submitted($submitted_form_data)) {
648 648
             throw new InvalidFormSubmissionException($this->form_name);
649 649
         }
650 650
         $this->form(true)->receive_form_submission($submitted_form_data);
651
-        if (! $this->form()->is_valid()) {
651
+        if ( ! $this->form()->is_valid()) {
652 652
             throw new InvalidFormSubmissionException(
653 653
                 $this->form_name,
654 654
                 sprintf(
Please login to merge, or discard this patch.
core/libraries/form_sections/form_handlers/SequentialStepForm.php 2 patches
Indentation   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -19,228 +19,228 @@
 block discarded – undo
19 19
 abstract class SequentialStepForm extends FormHandler implements SequentialStepFormInterface
20 20
 {
21 21
 
22
-    const REDIRECT_TO_NEXT_STEP    = 'redirect_to_next_step';
23
-
24
-    const REDIRECT_TO_CURRENT_STEP = 'redirect_to_current_step';
25
-
26
-    const REDIRECT_TO_PREV_STEP    = 'redirect_to_prev_step';
27
-
28
-    const REDIRECT_TO_OTHER        = 'redirect_to_other';
29
-
30
-    /**
31
-     * numerical value used for sorting form steps
32
-     *
33
-     * @var int $order
34
-     */
35
-    private $order = 1;
36
-
37
-    /**
38
-     * a final URL with all form related parameters added
39
-     * that will be used to advance to the next step
40
-     *
41
-     * @var string $redirect_url
42
-     */
43
-    private $redirect_url = '';
44
-
45
-    /**
46
-     * URL params in key value pairs
47
-     *
48
-     * @var array $redirect_args
49
-     */
50
-    private $redirect_args = array();
51
-
52
-    /**
53
-     * Which step should be redirected to after form processing.
54
-     * Usually after successfully processing this value would be REDIRECT_TO_NEXT_STEP
55
-     * If a form is invalid and requires errors to be corrected,
56
-     * then this value would be REDIRECT_TO_CURRENT_STEP so that form can be resubmitted
57
-     * Some form handlers do not have a form that is displayable,
58
-     * and only perform data processing, but if an error occurs,
59
-     * then this value needs to be set to REDIRECT_TO_PREV_STEP
60
-     * since the current step has no displayable content.
61
-     * if the form is completely finished, and needs to redirect to somewhere
62
-     * completely different, then this value will be REDIRECT_TO_OTHER
63
-     *
64
-     * @var string $redirect_to
65
-     */
66
-    private $redirect_to = SequentialStepForm::REDIRECT_TO_CURRENT_STEP;
67
-
68
-
69
-
70
-    /**
71
-     * SequentialStepForm constructor
72
-     *
73
-     * @param int         $order
74
-     * @param string      $form_name
75
-     * @param string      $admin_name
76
-     * @param string      $slug
77
-     * @param string      $form_action
78
-     * @param string      $form_config
79
-     * @param EE_Registry $registry
80
-     * @throws InvalidArgumentException
81
-     * @throws InvalidDataTypeException
82
-     * @throws DomainException
83
-     */
84
-    public function __construct(
85
-        $order,
86
-        $form_name,
87
-        $admin_name,
88
-        $slug,
89
-        $form_action = '',
90
-        $form_config = 'add_form_tags_and_submit',
91
-        EE_Registry $registry
92
-    ) {
93
-        $this->setOrder($order);
94
-        parent::__construct($form_name, $admin_name, $slug, $form_action, $form_config, $registry);
95
-    }
96
-
97
-
98
-
99
-    /**
100
-     * @return int
101
-     */
102
-    public function order()
103
-    {
104
-        return $this->order;
105
-    }
106
-
107
-
108
-
109
-    /**
110
-     * @param int $order
111
-     * @throws InvalidArgumentException
112
-     */
113
-    public function setOrder($order)
114
-    {
115
-        $order = absint($order);
116
-        if (! $order > 0) {
117
-            throw new InvalidArgumentException(
118
-                esc_html__('The form order property must be a positive integer.', 'event_espresso')
119
-            );
120
-        }
121
-        $this->order = $order;
122
-    }
123
-
124
-
125
-
126
-    /**
127
-     * @return string
128
-     */
129
-    public function redirectUrl()
130
-    {
131
-        return ! empty($this->redirect_args)
132
-            ? add_query_arg($this->redirect_args, $this->redirect_url)
133
-            : $this->redirect_url;
134
-    }
135
-
136
-
137
-
138
-    /**
139
-     * @param string $redirect_url
140
-     * @throws InvalidDataTypeException
141
-     * @throws InvalidArgumentException
142
-     */
143
-    public function setRedirectUrl($redirect_url)
144
-    {
145
-        if (! is_string($redirect_url)) {
146
-            throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string');
147
-        }
148
-        if (empty($redirect_url)) {
149
-            throw new InvalidArgumentException(
150
-                esc_html__('The redirect URL can not be an empty string.', 'event_espresso')
151
-            );
152
-        }
153
-        $this->redirect_url = $redirect_url;
154
-    }
155
-
156
-
157
-
158
-    /**
159
-     * @param array $redirect_args
160
-     * @throws InvalidDataTypeException
161
-     * @throws InvalidArgumentException
162
-     */
163
-    public function addRedirectArgs($redirect_args = array())
164
-    {
165
-        if (is_object($redirect_args)) {
166
-            throw new InvalidDataTypeException(
167
-                '$redirect_args',
168
-                $redirect_args,
169
-                'anything other than an object was expected.'
170
-            );
171
-        }
172
-        if (empty($redirect_args)) {
173
-            throw new InvalidArgumentException(
174
-                esc_html__('The redirect argument can not be an empty array.', 'event_espresso')
175
-            );
176
-        }
177
-        $this->redirect_args = array_merge($this->redirect_args, (array) $redirect_args);
178
-    }
179
-
180
-
181
-
182
-    /**
183
-     * @param array $redirect_arg_keys_to_remove
184
-     * @throws InvalidDataTypeException
185
-     * @throws InvalidArgumentException
186
-     */
187
-    public function removeRedirectArgs($redirect_arg_keys_to_remove = array())
188
-    {
189
-        if (is_object($redirect_arg_keys_to_remove)) {
190
-            throw new InvalidDataTypeException(
191
-                '$redirect_arg_keys_to_remove',
192
-                $redirect_arg_keys_to_remove,
193
-                'anything other than an object was expected.'
194
-            );
195
-        }
196
-        if (empty($redirect_arg_keys_to_remove)) {
197
-            throw new InvalidArgumentException(
198
-                esc_html__('The $redirect_arg_keys_to_remove argument can not be an empty array.', 'event_espresso')
199
-            );
200
-        }
201
-        foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) {
202
-            unset($this->redirect_args[ $redirect_arg_key ]);
203
-        }
204
-    }
205
-
206
-
207
-
208
-    /**
209
-     * @return string
210
-     */
211
-    public function redirectTo()
212
-    {
213
-        return $this->redirect_to;
214
-    }
215
-
216
-
217
-
218
-    /**
219
-     * @param string $redirect_to
220
-     * @throws InvalidDataTypeException
221
-     */
222
-    public function setRedirectTo($redirect_to)
223
-    {
224
-        if (
225
-            ! in_array(
226
-                $redirect_to,
227
-                array(
228
-                    SequentialStepForm::REDIRECT_TO_NEXT_STEP,
229
-                    SequentialStepForm::REDIRECT_TO_CURRENT_STEP,
230
-                    SequentialStepForm::REDIRECT_TO_PREV_STEP,
231
-                    SequentialStepForm::REDIRECT_TO_OTHER,
232
-                ),
233
-                true
234
-            )
235
-        ) {
236
-            throw new InvalidDataTypeException(
237
-                'setRedirectTo()',
238
-                $redirect_to,
239
-                'one of the SequentialStepForm class constants was expected.'
240
-            );
241
-        }
242
-        $this->redirect_to = $redirect_to;
243
-    }
22
+	const REDIRECT_TO_NEXT_STEP    = 'redirect_to_next_step';
23
+
24
+	const REDIRECT_TO_CURRENT_STEP = 'redirect_to_current_step';
25
+
26
+	const REDIRECT_TO_PREV_STEP    = 'redirect_to_prev_step';
27
+
28
+	const REDIRECT_TO_OTHER        = 'redirect_to_other';
29
+
30
+	/**
31
+	 * numerical value used for sorting form steps
32
+	 *
33
+	 * @var int $order
34
+	 */
35
+	private $order = 1;
36
+
37
+	/**
38
+	 * a final URL with all form related parameters added
39
+	 * that will be used to advance to the next step
40
+	 *
41
+	 * @var string $redirect_url
42
+	 */
43
+	private $redirect_url = '';
44
+
45
+	/**
46
+	 * URL params in key value pairs
47
+	 *
48
+	 * @var array $redirect_args
49
+	 */
50
+	private $redirect_args = array();
51
+
52
+	/**
53
+	 * Which step should be redirected to after form processing.
54
+	 * Usually after successfully processing this value would be REDIRECT_TO_NEXT_STEP
55
+	 * If a form is invalid and requires errors to be corrected,
56
+	 * then this value would be REDIRECT_TO_CURRENT_STEP so that form can be resubmitted
57
+	 * Some form handlers do not have a form that is displayable,
58
+	 * and only perform data processing, but if an error occurs,
59
+	 * then this value needs to be set to REDIRECT_TO_PREV_STEP
60
+	 * since the current step has no displayable content.
61
+	 * if the form is completely finished, and needs to redirect to somewhere
62
+	 * completely different, then this value will be REDIRECT_TO_OTHER
63
+	 *
64
+	 * @var string $redirect_to
65
+	 */
66
+	private $redirect_to = SequentialStepForm::REDIRECT_TO_CURRENT_STEP;
67
+
68
+
69
+
70
+	/**
71
+	 * SequentialStepForm constructor
72
+	 *
73
+	 * @param int         $order
74
+	 * @param string      $form_name
75
+	 * @param string      $admin_name
76
+	 * @param string      $slug
77
+	 * @param string      $form_action
78
+	 * @param string      $form_config
79
+	 * @param EE_Registry $registry
80
+	 * @throws InvalidArgumentException
81
+	 * @throws InvalidDataTypeException
82
+	 * @throws DomainException
83
+	 */
84
+	public function __construct(
85
+		$order,
86
+		$form_name,
87
+		$admin_name,
88
+		$slug,
89
+		$form_action = '',
90
+		$form_config = 'add_form_tags_and_submit',
91
+		EE_Registry $registry
92
+	) {
93
+		$this->setOrder($order);
94
+		parent::__construct($form_name, $admin_name, $slug, $form_action, $form_config, $registry);
95
+	}
96
+
97
+
98
+
99
+	/**
100
+	 * @return int
101
+	 */
102
+	public function order()
103
+	{
104
+		return $this->order;
105
+	}
106
+
107
+
108
+
109
+	/**
110
+	 * @param int $order
111
+	 * @throws InvalidArgumentException
112
+	 */
113
+	public function setOrder($order)
114
+	{
115
+		$order = absint($order);
116
+		if (! $order > 0) {
117
+			throw new InvalidArgumentException(
118
+				esc_html__('The form order property must be a positive integer.', 'event_espresso')
119
+			);
120
+		}
121
+		$this->order = $order;
122
+	}
123
+
124
+
125
+
126
+	/**
127
+	 * @return string
128
+	 */
129
+	public function redirectUrl()
130
+	{
131
+		return ! empty($this->redirect_args)
132
+			? add_query_arg($this->redirect_args, $this->redirect_url)
133
+			: $this->redirect_url;
134
+	}
135
+
136
+
137
+
138
+	/**
139
+	 * @param string $redirect_url
140
+	 * @throws InvalidDataTypeException
141
+	 * @throws InvalidArgumentException
142
+	 */
143
+	public function setRedirectUrl($redirect_url)
144
+	{
145
+		if (! is_string($redirect_url)) {
146
+			throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string');
147
+		}
148
+		if (empty($redirect_url)) {
149
+			throw new InvalidArgumentException(
150
+				esc_html__('The redirect URL can not be an empty string.', 'event_espresso')
151
+			);
152
+		}
153
+		$this->redirect_url = $redirect_url;
154
+	}
155
+
156
+
157
+
158
+	/**
159
+	 * @param array $redirect_args
160
+	 * @throws InvalidDataTypeException
161
+	 * @throws InvalidArgumentException
162
+	 */
163
+	public function addRedirectArgs($redirect_args = array())
164
+	{
165
+		if (is_object($redirect_args)) {
166
+			throw new InvalidDataTypeException(
167
+				'$redirect_args',
168
+				$redirect_args,
169
+				'anything other than an object was expected.'
170
+			);
171
+		}
172
+		if (empty($redirect_args)) {
173
+			throw new InvalidArgumentException(
174
+				esc_html__('The redirect argument can not be an empty array.', 'event_espresso')
175
+			);
176
+		}
177
+		$this->redirect_args = array_merge($this->redirect_args, (array) $redirect_args);
178
+	}
179
+
180
+
181
+
182
+	/**
183
+	 * @param array $redirect_arg_keys_to_remove
184
+	 * @throws InvalidDataTypeException
185
+	 * @throws InvalidArgumentException
186
+	 */
187
+	public function removeRedirectArgs($redirect_arg_keys_to_remove = array())
188
+	{
189
+		if (is_object($redirect_arg_keys_to_remove)) {
190
+			throw new InvalidDataTypeException(
191
+				'$redirect_arg_keys_to_remove',
192
+				$redirect_arg_keys_to_remove,
193
+				'anything other than an object was expected.'
194
+			);
195
+		}
196
+		if (empty($redirect_arg_keys_to_remove)) {
197
+			throw new InvalidArgumentException(
198
+				esc_html__('The $redirect_arg_keys_to_remove argument can not be an empty array.', 'event_espresso')
199
+			);
200
+		}
201
+		foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) {
202
+			unset($this->redirect_args[ $redirect_arg_key ]);
203
+		}
204
+	}
205
+
206
+
207
+
208
+	/**
209
+	 * @return string
210
+	 */
211
+	public function redirectTo()
212
+	{
213
+		return $this->redirect_to;
214
+	}
215
+
216
+
217
+
218
+	/**
219
+	 * @param string $redirect_to
220
+	 * @throws InvalidDataTypeException
221
+	 */
222
+	public function setRedirectTo($redirect_to)
223
+	{
224
+		if (
225
+			! in_array(
226
+				$redirect_to,
227
+				array(
228
+					SequentialStepForm::REDIRECT_TO_NEXT_STEP,
229
+					SequentialStepForm::REDIRECT_TO_CURRENT_STEP,
230
+					SequentialStepForm::REDIRECT_TO_PREV_STEP,
231
+					SequentialStepForm::REDIRECT_TO_OTHER,
232
+				),
233
+				true
234
+			)
235
+		) {
236
+			throw new InvalidDataTypeException(
237
+				'setRedirectTo()',
238
+				$redirect_to,
239
+				'one of the SequentialStepForm class constants was expected.'
240
+			);
241
+		}
242
+		$this->redirect_to = $redirect_to;
243
+	}
244 244
 }
245 245
 // End of file SequentialStepForm.php
246 246
 // Location: /SequentialStepForm.php
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
     public function setOrder($order)
114 114
     {
115 115
         $order = absint($order);
116
-        if (! $order > 0) {
116
+        if ( ! $order > 0) {
117 117
             throw new InvalidArgumentException(
118 118
                 esc_html__('The form order property must be a positive integer.', 'event_espresso')
119 119
             );
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
      */
143 143
     public function setRedirectUrl($redirect_url)
144 144
     {
145
-        if (! is_string($redirect_url)) {
145
+        if ( ! is_string($redirect_url)) {
146 146
             throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string');
147 147
         }
148 148
         if (empty($redirect_url)) {
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
             );
200 200
         }
201 201
         foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) {
202
-            unset($this->redirect_args[ $redirect_arg_key ]);
202
+            unset($this->redirect_args[$redirect_arg_key]);
203 203
         }
204 204
     }
205 205
 
Please login to merge, or discard this patch.