@@ -15,15 +15,15 @@ discard block |
||
15 | 15 | */ |
16 | 16 | abstract class JsonDataWordpressOption extends WordPressOption |
17 | 17 | { |
18 | - /** |
|
18 | + /** |
|
19 | 19 | * @var array|mixed|stdClass |
20 | 20 | */ |
21 | - private $options = []; |
|
21 | + private $options = []; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @var JsonDataHandler|null |
|
25 | - */ |
|
26 | - private ?JsonDataHandler $json_data_handler; |
|
23 | + /** |
|
24 | + * @var JsonDataHandler|null |
|
25 | + */ |
|
26 | + private ?JsonDataHandler $json_data_handler; |
|
27 | 27 | |
28 | 28 | |
29 | 29 | /** |
@@ -40,12 +40,12 @@ discard block |
||
40 | 40 | $default_value, |
41 | 41 | bool $autoload = false |
42 | 42 | ) { |
43 | - $this->json_data_handler = $json_data_handler; |
|
43 | + $this->json_data_handler = $json_data_handler; |
|
44 | 44 | if (! $this->json_data_handler->dataType()) { |
45 | 45 | $this->json_data_handler->configure(JsonDataHandler::DATA_TYPE_OBJECT); |
46 | 46 | } |
47 | - parent::__construct($option_name, $default_value, $autoload); |
|
48 | - } |
|
47 | + parent::__construct($option_name, $default_value, $autoload); |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | 51 | /** |
@@ -53,59 +53,59 @@ discard block |
||
53 | 53 | * @return int |
54 | 54 | */ |
55 | 55 | public function updateOption($value): int |
56 | - { |
|
57 | - if (parent::updateOption($this->json_data_handler->encodeData($value))) { |
|
58 | - $this->options = $value; |
|
56 | + { |
|
57 | + if (parent::updateOption($this->json_data_handler->encodeData($value))) { |
|
58 | + $this->options = $value; |
|
59 | 59 | return WordPressOption::UPDATE_SUCCESS; |
60 | 60 | } |
61 | 61 | return WordPressOption::UPDATE_ERROR; |
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @param string $property |
|
67 | - * @param mixed $value |
|
68 | - * @return void |
|
69 | - */ |
|
70 | - public function addProperty(string $property, $value) |
|
71 | - { |
|
72 | - $options = $this->getAll(); |
|
73 | - $options->{$property} = $value; |
|
74 | - $this->updateOption($options); |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * @param string $property |
|
80 | - * @return mixed |
|
81 | - */ |
|
82 | - public function getProperty(string $property) |
|
83 | - { |
|
84 | - $options = $this->getAll(); |
|
85 | - return property_exists($options, $property) ? $options->{$property} : null; |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @param string $property |
|
67 | + * @param mixed $value |
|
68 | + * @return void |
|
69 | + */ |
|
70 | + public function addProperty(string $property, $value) |
|
71 | + { |
|
72 | + $options = $this->getAll(); |
|
73 | + $options->{$property} = $value; |
|
74 | + $this->updateOption($options); |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * @param string $property |
|
80 | + * @return mixed |
|
81 | + */ |
|
82 | + public function getProperty(string $property) |
|
83 | + { |
|
84 | + $options = $this->getAll(); |
|
85 | + return property_exists($options, $property) ? $options->{$property} : null; |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | 90 | * @return array|mixed|stdClass |
91 | - */ |
|
92 | - public function getAll() |
|
91 | + */ |
|
92 | + public function getAll() |
|
93 | 93 | { |
94 | - if (empty($this->options)) { |
|
94 | + if (empty($this->options)) { |
|
95 | 95 | $this->options = $this->json_data_handler->decodeJson($this->loadOption()); |
96 | - } |
|
97 | - return $this->options; |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @param string $property |
|
103 | - * @return void |
|
104 | - */ |
|
105 | - public function removeProperty(string $property) |
|
106 | - { |
|
107 | - $options = $this->getAll(); |
|
108 | - unset($options->{$property}); |
|
109 | - $this->updateOption($options); |
|
110 | - } |
|
96 | + } |
|
97 | + return $this->options; |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @param string $property |
|
103 | + * @return void |
|
104 | + */ |
|
105 | + public function removeProperty(string $property) |
|
106 | + { |
|
107 | + $options = $this->getAll(); |
|
108 | + unset($options->{$property}); |
|
109 | + $this->updateOption($options); |
|
110 | + } |
|
111 | 111 | } |
@@ -41,7 +41,7 @@ |
||
41 | 41 | bool $autoload = false |
42 | 42 | ) { |
43 | 43 | $this->json_data_handler = $json_data_handler; |
44 | - if (! $this->json_data_handler->dataType()) { |
|
44 | + if ( ! $this->json_data_handler->dataType()) { |
|
45 | 45 | $this->json_data_handler->configure(JsonDataHandler::DATA_TYPE_OBJECT); |
46 | 46 | } |
47 | 47 | parent::__construct($option_name, $default_value, $autoload); |
@@ -17,135 +17,135 @@ discard block |
||
17 | 17 | */ |
18 | 18 | abstract class WordPressOption |
19 | 19 | { |
20 | - const NOT_SET_YET = 'wordpress-option-value-not-yet-set'; |
|
21 | - |
|
22 | - /** |
|
23 | - * WordPress makes it difficult to determine if an option successfully saved or not, |
|
24 | - * which is sometimes really important to know, especially if the information you are saving is critical. |
|
25 | - * The following options allow us to have a better chance of knowing when an update actually failed |
|
26 | - * or when everything is OK but it just didn't update because the value hasn't changed. |
|
27 | - */ |
|
28 | - const UPDATE_SUCCESS = 1; |
|
29 | - |
|
30 | - const UPDATE_NONE = 0; |
|
31 | - |
|
32 | - const UPDATE_ERROR = -1; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var boolean |
|
36 | - */ |
|
37 | - private $autoload = false; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var mixed |
|
41 | - */ |
|
42 | - private $default_value = null; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - private $option_name = ''; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var mixed |
|
51 | - */ |
|
52 | - private $value = WordPressOption::NOT_SET_YET; |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * WordPressOption constructor. |
|
57 | - * |
|
58 | - * @param bool $autoload |
|
59 | - * @param mixed $default_value |
|
60 | - * @param string $option_name |
|
61 | - */ |
|
62 | - public function __construct(string $option_name, $default_value, bool $autoload = false) |
|
63 | - { |
|
20 | + const NOT_SET_YET = 'wordpress-option-value-not-yet-set'; |
|
21 | + |
|
22 | + /** |
|
23 | + * WordPress makes it difficult to determine if an option successfully saved or not, |
|
24 | + * which is sometimes really important to know, especially if the information you are saving is critical. |
|
25 | + * The following options allow us to have a better chance of knowing when an update actually failed |
|
26 | + * or when everything is OK but it just didn't update because the value hasn't changed. |
|
27 | + */ |
|
28 | + const UPDATE_SUCCESS = 1; |
|
29 | + |
|
30 | + const UPDATE_NONE = 0; |
|
31 | + |
|
32 | + const UPDATE_ERROR = -1; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var boolean |
|
36 | + */ |
|
37 | + private $autoload = false; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var mixed |
|
41 | + */ |
|
42 | + private $default_value = null; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + private $option_name = ''; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var mixed |
|
51 | + */ |
|
52 | + private $value = WordPressOption::NOT_SET_YET; |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * WordPressOption constructor. |
|
57 | + * |
|
58 | + * @param bool $autoload |
|
59 | + * @param mixed $default_value |
|
60 | + * @param string $option_name |
|
61 | + */ |
|
62 | + public function __construct(string $option_name, $default_value, bool $autoload = false) |
|
63 | + { |
|
64 | 64 | $this->setAutoload($autoload); |
65 | - $this->setDefaultValue($default_value); |
|
66 | - $this->setOptionName($option_name); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * @param bool|string $autoload |
|
72 | - */ |
|
73 | - public function setAutoload($autoload): void |
|
74 | - { |
|
75 | - $this->autoload = filter_var($autoload, FILTER_VALIDATE_BOOLEAN); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * @param mixed $default_value |
|
81 | - */ |
|
82 | - public function setDefaultValue($default_value): void |
|
83 | - { |
|
84 | - $this->default_value = $default_value; |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * @param string $option_name |
|
90 | - */ |
|
91 | - public function setOptionName(string $option_name): void |
|
92 | - { |
|
93 | - $this->option_name = sanitize_key($option_name); |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * @return string |
|
99 | - */ |
|
100 | - public function optionExists(): string |
|
101 | - { |
|
65 | + $this->setDefaultValue($default_value); |
|
66 | + $this->setOptionName($option_name); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * @param bool|string $autoload |
|
72 | + */ |
|
73 | + public function setAutoload($autoload): void |
|
74 | + { |
|
75 | + $this->autoload = filter_var($autoload, FILTER_VALIDATE_BOOLEAN); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * @param mixed $default_value |
|
81 | + */ |
|
82 | + public function setDefaultValue($default_value): void |
|
83 | + { |
|
84 | + $this->default_value = $default_value; |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * @param string $option_name |
|
90 | + */ |
|
91 | + public function setOptionName(string $option_name): void |
|
92 | + { |
|
93 | + $this->option_name = sanitize_key($option_name); |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * @return string |
|
99 | + */ |
|
100 | + public function optionExists(): string |
|
101 | + { |
|
102 | 102 | return get_option($this->option_name, WordPressOption::NOT_SET_YET) !== WordPressOption::NOT_SET_YET; |
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - public function getOptionName(): string |
|
110 | - { |
|
111 | - return $this->option_name; |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @return false|mixed|void |
|
117 | - */ |
|
118 | - public function loadOption() |
|
119 | - { |
|
120 | - if ($this->value === WordPressOption::NOT_SET_YET) { |
|
121 | - $this->value = get_option($this->option_name, $this->default_value); |
|
122 | - } |
|
123 | - return $this->value; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @param $value |
|
129 | - * @return int |
|
130 | - */ |
|
131 | - public function updateOption($value): int |
|
132 | - { |
|
133 | - // don't update if value has not changed since last update |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + public function getOptionName(): string |
|
110 | + { |
|
111 | + return $this->option_name; |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @return false|mixed|void |
|
117 | + */ |
|
118 | + public function loadOption() |
|
119 | + { |
|
120 | + if ($this->value === WordPressOption::NOT_SET_YET) { |
|
121 | + $this->value = get_option($this->option_name, $this->default_value); |
|
122 | + } |
|
123 | + return $this->value; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @param $value |
|
129 | + * @return int |
|
130 | + */ |
|
131 | + public function updateOption($value): int |
|
132 | + { |
|
133 | + // don't update if value has not changed since last update |
|
134 | 134 | if ($this->valueIsUnchanged($value)) { |
135 | - return WordPressOption::UPDATE_NONE; |
|
136 | - } |
|
135 | + return WordPressOption::UPDATE_NONE; |
|
136 | + } |
|
137 | 137 | $this->value = $value; |
138 | - // because the options for updating differ when adding an option for the first time |
|
139 | - // we use the WordPressOption::NOT_SET_YET to determine if things already exist in the db |
|
138 | + // because the options for updating differ when adding an option for the first time |
|
139 | + // we use the WordPressOption::NOT_SET_YET to determine if things already exist in the db |
|
140 | 140 | $updated = $this->optionExists() |
141 | 141 | ? update_option($this->option_name, $this->value) |
142 | 142 | : add_option($this->option_name, $this->value, '', $this->autoload()); |
143 | 143 | |
144 | - if ($updated) { |
|
145 | - return WordPressOption::UPDATE_SUCCESS; |
|
146 | - } |
|
147 | - return WordPressOption::UPDATE_ERROR; |
|
148 | - } |
|
144 | + if ($updated) { |
|
145 | + return WordPressOption::UPDATE_SUCCESS; |
|
146 | + } |
|
147 | + return WordPressOption::UPDATE_ERROR; |
|
148 | + } |
|
149 | 149 | |
150 | 150 | |
151 | 151 | private function valueIsUnchanged($value): bool |
@@ -160,13 +160,13 @@ discard block |
||
160 | 160 | } |
161 | 161 | |
162 | 162 | |
163 | - /** |
|
164 | - * @return string |
|
165 | - */ |
|
166 | - private function autoload(): string |
|
167 | - { |
|
168 | - return $this->autoload ? 'yes' : 'no'; |
|
169 | - } |
|
163 | + /** |
|
164 | + * @return string |
|
165 | + */ |
|
166 | + private function autoload(): string |
|
167 | + { |
|
168 | + return $this->autoload ? 'yes' : 'no'; |
|
169 | + } |
|
170 | 170 | |
171 | 171 | |
172 | 172 | /** |
@@ -16,112 +16,112 @@ |
||
16 | 16 | */ |
17 | 17 | class StatusChangeNotice extends WordPressOption |
18 | 18 | { |
19 | - public function __construct() |
|
20 | - { |
|
21 | - parent::__construct('ee_hide_status_change_notices_for_users', [], false); |
|
22 | - } |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + parent::__construct('ee_hide_status_change_notices_for_users', [], false); |
|
22 | + } |
|
23 | 23 | |
24 | 24 | |
25 | - public static function loadAssets() |
|
26 | - { |
|
27 | - wp_enqueue_style( |
|
28 | - 'status_change_notice', |
|
29 | - EE_PLUGIN_DIR_URL . 'core/domain/services/admin/notices/status_change/status_change_notice.css', |
|
30 | - ['espresso_menu'], |
|
31 | - EVENT_ESPRESSO_VERSION |
|
32 | - ); |
|
33 | - wp_enqueue_script( |
|
34 | - 'status_change_notice', |
|
35 | - EE_PLUGIN_DIR_URL . 'core/domain/services/admin/notices/status_change/status_change_notice.js', |
|
36 | - ['jquery'], |
|
37 | - EVENT_ESPRESSO_VERSION, |
|
38 | - true |
|
39 | - ); |
|
40 | - wp_localize_script( |
|
41 | - 'status_change_notice', |
|
42 | - 'eeStatusChangeNotice', |
|
43 | - [ |
|
44 | - 'failed_request_msg' => wp_strip_all_tags( |
|
45 | - __( |
|
46 | - 'Request failed. The server returned status code: ', |
|
47 | - 'event_espresso' |
|
48 | - ) |
|
49 | - ), |
|
50 | - 'unknown_error_msg' => wp_strip_all_tags( |
|
51 | - __( |
|
52 | - 'Oops... an unknown error has occurred on the server and this notice could not be dismissed.', |
|
53 | - 'event_espresso' |
|
54 | - ) |
|
55 | - ), |
|
56 | - ] |
|
57 | - ); |
|
58 | - } |
|
25 | + public static function loadAssets() |
|
26 | + { |
|
27 | + wp_enqueue_style( |
|
28 | + 'status_change_notice', |
|
29 | + EE_PLUGIN_DIR_URL . 'core/domain/services/admin/notices/status_change/status_change_notice.css', |
|
30 | + ['espresso_menu'], |
|
31 | + EVENT_ESPRESSO_VERSION |
|
32 | + ); |
|
33 | + wp_enqueue_script( |
|
34 | + 'status_change_notice', |
|
35 | + EE_PLUGIN_DIR_URL . 'core/domain/services/admin/notices/status_change/status_change_notice.js', |
|
36 | + ['jquery'], |
|
37 | + EVENT_ESPRESSO_VERSION, |
|
38 | + true |
|
39 | + ); |
|
40 | + wp_localize_script( |
|
41 | + 'status_change_notice', |
|
42 | + 'eeStatusChangeNotice', |
|
43 | + [ |
|
44 | + 'failed_request_msg' => wp_strip_all_tags( |
|
45 | + __( |
|
46 | + 'Request failed. The server returned status code: ', |
|
47 | + 'event_espresso' |
|
48 | + ) |
|
49 | + ), |
|
50 | + 'unknown_error_msg' => wp_strip_all_tags( |
|
51 | + __( |
|
52 | + 'Oops... an unknown error has occurred on the server and this notice could not be dismissed.', |
|
53 | + 'event_espresso' |
|
54 | + ) |
|
55 | + ), |
|
56 | + ] |
|
57 | + ); |
|
58 | + } |
|
59 | 59 | |
60 | 60 | |
61 | - public function display(string $context, string $page_slug): string |
|
62 | - { |
|
63 | - return $this->isNotDismissed() |
|
64 | - ? EEH_Template::display_template( |
|
65 | - __DIR__ . '/status_change_notice.template.php', |
|
66 | - [ |
|
61 | + public function display(string $context, string $page_slug): string |
|
62 | + { |
|
63 | + return $this->isNotDismissed() |
|
64 | + ? EEH_Template::display_template( |
|
65 | + __DIR__ . '/status_change_notice.template.php', |
|
66 | + [ |
|
67 | 67 | 'context' => $context, |
68 | 68 | 'page_slug' => ! empty($page_slug) ? "$page_slug-page" : '', |
69 | - ], |
|
70 | - true |
|
71 | - ) |
|
72 | - : ''; |
|
73 | - } |
|
69 | + ], |
|
70 | + true |
|
71 | + ) |
|
72 | + : ''; |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | - /** |
|
77 | - * @return int |
|
78 | - * @throws RuntimeException |
|
79 | - */ |
|
80 | - public function dismiss(): int |
|
81 | - { |
|
82 | - $user = $this->getCurrentUser(); |
|
83 | - $dismissed = (array) $this->loadOption(); |
|
84 | - if (! in_array($user, $dismissed)) { |
|
85 | - $dismissed[] = $user; |
|
86 | - } |
|
87 | - return $this->updateOption($dismissed); |
|
88 | - } |
|
76 | + /** |
|
77 | + * @return int |
|
78 | + * @throws RuntimeException |
|
79 | + */ |
|
80 | + public function dismiss(): int |
|
81 | + { |
|
82 | + $user = $this->getCurrentUser(); |
|
83 | + $dismissed = (array) $this->loadOption(); |
|
84 | + if (! in_array($user, $dismissed)) { |
|
85 | + $dismissed[] = $user; |
|
86 | + } |
|
87 | + return $this->updateOption($dismissed); |
|
88 | + } |
|
89 | 89 | |
90 | 90 | |
91 | - /** |
|
92 | - * @return bool |
|
93 | - * @throws RuntimeException |
|
94 | - */ |
|
95 | - public function isDismissed(): bool |
|
96 | - { |
|
97 | - $user = $this->getCurrentUser(); |
|
98 | - $dismissed = (array) $this->loadOption(); |
|
99 | - return in_array($user, $dismissed); |
|
100 | - } |
|
91 | + /** |
|
92 | + * @return bool |
|
93 | + * @throws RuntimeException |
|
94 | + */ |
|
95 | + public function isDismissed(): bool |
|
96 | + { |
|
97 | + $user = $this->getCurrentUser(); |
|
98 | + $dismissed = (array) $this->loadOption(); |
|
99 | + return in_array($user, $dismissed); |
|
100 | + } |
|
101 | 101 | |
102 | 102 | |
103 | - /** |
|
104 | - * @return bool |
|
105 | - * @throws RuntimeException |
|
106 | - */ |
|
107 | - public function isNotDismissed(): bool |
|
108 | - { |
|
109 | - return ! $this->isDismissed(); |
|
110 | - } |
|
103 | + /** |
|
104 | + * @return bool |
|
105 | + * @throws RuntimeException |
|
106 | + */ |
|
107 | + public function isNotDismissed(): bool |
|
108 | + { |
|
109 | + return ! $this->isDismissed(); |
|
110 | + } |
|
111 | 111 | |
112 | 112 | |
113 | - /** |
|
114 | - * @return string |
|
115 | - * @throws RuntimeException |
|
116 | - */ |
|
117 | - private function getCurrentUser(): string |
|
118 | - { |
|
119 | - $user = wp_get_current_user(); |
|
120 | - if (! $user instanceof WP_User || ! $user->exists()) { |
|
121 | - throw new RuntimeException( |
|
122 | - esc_html__('A valid WP User could not be retrieved.', 'event_espresso') |
|
123 | - ); |
|
124 | - } |
|
125 | - return $user->user_login; |
|
126 | - } |
|
113 | + /** |
|
114 | + * @return string |
|
115 | + * @throws RuntimeException |
|
116 | + */ |
|
117 | + private function getCurrentUser(): string |
|
118 | + { |
|
119 | + $user = wp_get_current_user(); |
|
120 | + if (! $user instanceof WP_User || ! $user->exists()) { |
|
121 | + throw new RuntimeException( |
|
122 | + esc_html__('A valid WP User could not be retrieved.', 'event_espresso') |
|
123 | + ); |
|
124 | + } |
|
125 | + return $user->user_login; |
|
126 | + } |
|
127 | 127 | } |
@@ -26,13 +26,13 @@ discard block |
||
26 | 26 | { |
27 | 27 | wp_enqueue_style( |
28 | 28 | 'status_change_notice', |
29 | - EE_PLUGIN_DIR_URL . 'core/domain/services/admin/notices/status_change/status_change_notice.css', |
|
29 | + EE_PLUGIN_DIR_URL.'core/domain/services/admin/notices/status_change/status_change_notice.css', |
|
30 | 30 | ['espresso_menu'], |
31 | 31 | EVENT_ESPRESSO_VERSION |
32 | 32 | ); |
33 | 33 | wp_enqueue_script( |
34 | 34 | 'status_change_notice', |
35 | - EE_PLUGIN_DIR_URL . 'core/domain/services/admin/notices/status_change/status_change_notice.js', |
|
35 | + EE_PLUGIN_DIR_URL.'core/domain/services/admin/notices/status_change/status_change_notice.js', |
|
36 | 36 | ['jquery'], |
37 | 37 | EVENT_ESPRESSO_VERSION, |
38 | 38 | true |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | { |
63 | 63 | return $this->isNotDismissed() |
64 | 64 | ? EEH_Template::display_template( |
65 | - __DIR__ . '/status_change_notice.template.php', |
|
65 | + __DIR__.'/status_change_notice.template.php', |
|
66 | 66 | [ |
67 | 67 | 'context' => $context, |
68 | 68 | 'page_slug' => ! empty($page_slug) ? "$page_slug-page" : '', |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | { |
82 | 82 | $user = $this->getCurrentUser(); |
83 | 83 | $dismissed = (array) $this->loadOption(); |
84 | - if (! in_array($user, $dismissed)) { |
|
84 | + if ( ! in_array($user, $dismissed)) { |
|
85 | 85 | $dismissed[] = $user; |
86 | 86 | } |
87 | 87 | return $this->updateOption($dismissed); |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | private function getCurrentUser(): string |
118 | 118 | { |
119 | 119 | $user = wp_get_current_user(); |
120 | - if (! $user instanceof WP_User || ! $user->exists()) { |
|
120 | + if ( ! $user instanceof WP_User || ! $user->exists()) { |
|
121 | 121 | throw new RuntimeException( |
122 | 122 | esc_html__('A valid WP User could not be retrieved.', 'event_espresso') |
123 | 123 | ); |
@@ -30,86 +30,86 @@ |
||
30 | 30 | */ |
31 | 31 | class ConfirmDeletion |
32 | 32 | { |
33 | - /** |
|
34 | - * @var NodeGroupDao |
|
35 | - */ |
|
36 | - private $dao; |
|
33 | + /** |
|
34 | + * @var NodeGroupDao |
|
35 | + */ |
|
36 | + private $dao; |
|
37 | 37 | |
38 | - /** |
|
39 | - * ConfirmDeletion constructor. |
|
40 | - * @param NodeGroupDao $dao |
|
41 | - */ |
|
42 | - public function __construct( |
|
43 | - NodeGroupDao $dao |
|
44 | - ) { |
|
38 | + /** |
|
39 | + * ConfirmDeletion constructor. |
|
40 | + * @param NodeGroupDao $dao |
|
41 | + */ |
|
42 | + public function __construct( |
|
43 | + NodeGroupDao $dao |
|
44 | + ) { |
|
45 | 45 | |
46 | - $this->dao = $dao; |
|
47 | - } |
|
46 | + $this->dao = $dao; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Redirects to the batch job for deleting events if the form submission is valid, otherwise back to the deletion |
|
51 | - * preview page. |
|
52 | - * @since 4.10.12.p |
|
53 | - * @param $request_data |
|
54 | - * @param $admin_base_url |
|
55 | - * @throws EE_Error |
|
56 | - * @throws InvalidArgumentException |
|
57 | - * @throws InvalidDataTypeException |
|
58 | - * @throws InvalidInterfaceException |
|
59 | - * @throws ReflectionException |
|
60 | - * @throws UnexpectedEntityException |
|
61 | - */ |
|
62 | - public function handle($request_data, $admin_base_url) |
|
63 | - { |
|
64 | - $deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : ''; |
|
65 | - $models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code); |
|
66 | - $form = new ConfirmEventDeletionForm($models_and_ids_to_delete['Event']); |
|
67 | - // Initialize the form from the request, and check if its valid. |
|
68 | - $form->receive_form_submission($request_data); |
|
69 | - if ($form->is_valid()) { |
|
70 | - // Redirect the user to the deletion batch job. |
|
71 | - EEH_URL::safeRedirectAndExit( |
|
72 | - EE_Admin_Page::add_query_args_and_nonce( |
|
73 | - array( |
|
74 | - 'page' => EED_Batch::PAGE_SLUG, |
|
75 | - 'batch' => EED_Batch::batch_job, |
|
76 | - 'deletion_job_code' => $deletion_job_code, |
|
77 | - 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion'), |
|
78 | - 'return_url' => urlencode( |
|
79 | - add_query_arg( |
|
80 | - [ |
|
81 | - 'status' => 'trash' |
|
82 | - ], |
|
83 | - EVENTS_ADMIN_URL |
|
84 | - ) |
|
85 | - ) |
|
86 | - ), |
|
87 | - admin_url() |
|
88 | - ) |
|
89 | - ); |
|
90 | - } |
|
91 | - // Dont' use $form->submission_error_message() because it adds the form input's label in front |
|
92 | - // of each validation error which ends up looking quite confusing. |
|
93 | - $validation_errors = $form->get_validation_errors_accumulated(); |
|
94 | - foreach ($validation_errors as $validation_error) { |
|
95 | - EE_Error::add_error( |
|
96 | - $validation_error->getMessage(), |
|
97 | - __FILE__, |
|
98 | - __FUNCTION__, |
|
99 | - __LINE__ |
|
100 | - ); |
|
101 | - } |
|
49 | + /** |
|
50 | + * Redirects to the batch job for deleting events if the form submission is valid, otherwise back to the deletion |
|
51 | + * preview page. |
|
52 | + * @since 4.10.12.p |
|
53 | + * @param $request_data |
|
54 | + * @param $admin_base_url |
|
55 | + * @throws EE_Error |
|
56 | + * @throws InvalidArgumentException |
|
57 | + * @throws InvalidDataTypeException |
|
58 | + * @throws InvalidInterfaceException |
|
59 | + * @throws ReflectionException |
|
60 | + * @throws UnexpectedEntityException |
|
61 | + */ |
|
62 | + public function handle($request_data, $admin_base_url) |
|
63 | + { |
|
64 | + $deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : ''; |
|
65 | + $models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code); |
|
66 | + $form = new ConfirmEventDeletionForm($models_and_ids_to_delete['Event']); |
|
67 | + // Initialize the form from the request, and check if its valid. |
|
68 | + $form->receive_form_submission($request_data); |
|
69 | + if ($form->is_valid()) { |
|
70 | + // Redirect the user to the deletion batch job. |
|
71 | + EEH_URL::safeRedirectAndExit( |
|
72 | + EE_Admin_Page::add_query_args_and_nonce( |
|
73 | + array( |
|
74 | + 'page' => EED_Batch::PAGE_SLUG, |
|
75 | + 'batch' => EED_Batch::batch_job, |
|
76 | + 'deletion_job_code' => $deletion_job_code, |
|
77 | + 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion'), |
|
78 | + 'return_url' => urlencode( |
|
79 | + add_query_arg( |
|
80 | + [ |
|
81 | + 'status' => 'trash' |
|
82 | + ], |
|
83 | + EVENTS_ADMIN_URL |
|
84 | + ) |
|
85 | + ) |
|
86 | + ), |
|
87 | + admin_url() |
|
88 | + ) |
|
89 | + ); |
|
90 | + } |
|
91 | + // Dont' use $form->submission_error_message() because it adds the form input's label in front |
|
92 | + // of each validation error which ends up looking quite confusing. |
|
93 | + $validation_errors = $form->get_validation_errors_accumulated(); |
|
94 | + foreach ($validation_errors as $validation_error) { |
|
95 | + EE_Error::add_error( |
|
96 | + $validation_error->getMessage(), |
|
97 | + __FILE__, |
|
98 | + __FUNCTION__, |
|
99 | + __LINE__ |
|
100 | + ); |
|
101 | + } |
|
102 | 102 | |
103 | - EEH_URL::safeRedirectAndExit( |
|
104 | - EE_Admin_Page::add_query_args_and_nonce( |
|
105 | - [ |
|
106 | - 'action' => 'preview_deletion', |
|
107 | - 'deletion_job_code' => $deletion_job_code |
|
108 | - ], |
|
109 | - $admin_base_url |
|
110 | - ) |
|
111 | - ); |
|
112 | - } |
|
103 | + EEH_URL::safeRedirectAndExit( |
|
104 | + EE_Admin_Page::add_query_args_and_nonce( |
|
105 | + [ |
|
106 | + 'action' => 'preview_deletion', |
|
107 | + 'deletion_job_code' => $deletion_job_code |
|
108 | + ], |
|
109 | + $admin_base_url |
|
110 | + ) |
|
111 | + ); |
|
112 | + } |
|
113 | 113 | } |
114 | 114 | // End of file ConfirmDeletion.php |
115 | 115 | // Location: EventEspresso\core\domain\services\admin\events\data/ConfirmDeletion.php |
@@ -6,80 +6,80 @@ |
||
6 | 6 | */ |
7 | 7 | class EE_Float_Field extends EE_Model_Field_Base |
8 | 8 | { |
9 | - /** |
|
10 | - * @var EE_Currency_Config |
|
11 | - */ |
|
12 | - protected $currency; |
|
9 | + /** |
|
10 | + * @var EE_Currency_Config |
|
11 | + */ |
|
12 | + protected $currency; |
|
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * @param string $table_column |
|
17 | - * @param string $nicename |
|
18 | - * @param bool $nullable |
|
19 | - * @param null $default_value |
|
20 | - */ |
|
21 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
22 | - { |
|
23 | - $this->currency = EE_Config::instance()->currency instanceof EE_Currency_Config |
|
15 | + /** |
|
16 | + * @param string $table_column |
|
17 | + * @param string $nicename |
|
18 | + * @param bool $nullable |
|
19 | + * @param null $default_value |
|
20 | + */ |
|
21 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
22 | + { |
|
23 | + $this->currency = EE_Config::instance()->currency instanceof EE_Currency_Config |
|
24 | 24 | ? EE_Config::instance()->currency |
25 | 25 | : new EE_Currency_Config(); |
26 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
27 | - $this->setSchemaType('number'); |
|
28 | - } |
|
26 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
27 | + $this->setSchemaType('number'); |
|
28 | + } |
|
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * If provided a string, strips out number-related formatting, like commas, periods, spaces, other junk, etc. |
|
33 | - * However, treats commas and periods as thousand-separators ro decimal marks, as indicate by the config's currency. |
|
34 | - * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first. |
|
35 | - * Returns a float |
|
36 | - * |
|
37 | - * @param float|string $value_inputted_for_field_on_model_object |
|
38 | - * @return float |
|
39 | - */ |
|
40 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
41 | - { |
|
42 | - // remove whitespaces and thousands separators |
|
43 | - if (is_string($value_inputted_for_field_on_model_object)) { |
|
44 | - $value_inputted_for_field_on_model_object = str_replace( |
|
45 | - array(" ", $this->currency->thsnds), |
|
46 | - "", |
|
47 | - $value_inputted_for_field_on_model_object |
|
48 | - ); |
|
49 | - // normalize it so periods are decimal marks (we don't care where you're from: we're talking PHP now) |
|
50 | - $value_inputted_for_field_on_model_object = str_replace( |
|
51 | - $this->currency->dec_mrk, |
|
52 | - ".", |
|
53 | - $value_inputted_for_field_on_model_object |
|
54 | - ); |
|
55 | - // double-check there's absolutely nothing left on this string besides numbers |
|
56 | - $value_inputted_for_field_on_model_object = preg_replace( |
|
57 | - "/[^0-9,.]/", |
|
58 | - "", |
|
59 | - $value_inputted_for_field_on_model_object |
|
60 | - ); |
|
61 | - } |
|
62 | - return floatval($value_inputted_for_field_on_model_object); |
|
63 | - } |
|
31 | + /** |
|
32 | + * If provided a string, strips out number-related formatting, like commas, periods, spaces, other junk, etc. |
|
33 | + * However, treats commas and periods as thousand-separators ro decimal marks, as indicate by the config's currency. |
|
34 | + * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first. |
|
35 | + * Returns a float |
|
36 | + * |
|
37 | + * @param float|string $value_inputted_for_field_on_model_object |
|
38 | + * @return float |
|
39 | + */ |
|
40 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
41 | + { |
|
42 | + // remove whitespaces and thousands separators |
|
43 | + if (is_string($value_inputted_for_field_on_model_object)) { |
|
44 | + $value_inputted_for_field_on_model_object = str_replace( |
|
45 | + array(" ", $this->currency->thsnds), |
|
46 | + "", |
|
47 | + $value_inputted_for_field_on_model_object |
|
48 | + ); |
|
49 | + // normalize it so periods are decimal marks (we don't care where you're from: we're talking PHP now) |
|
50 | + $value_inputted_for_field_on_model_object = str_replace( |
|
51 | + $this->currency->dec_mrk, |
|
52 | + ".", |
|
53 | + $value_inputted_for_field_on_model_object |
|
54 | + ); |
|
55 | + // double-check there's absolutely nothing left on this string besides numbers |
|
56 | + $value_inputted_for_field_on_model_object = preg_replace( |
|
57 | + "/[^0-9,.]/", |
|
58 | + "", |
|
59 | + $value_inputted_for_field_on_model_object |
|
60 | + ); |
|
61 | + } |
|
62 | + return floatval($value_inputted_for_field_on_model_object); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Returns the number formatted according to local custom (set by the country of the blog). |
|
67 | - * |
|
68 | - * @param float $value_on_field_to_be_outputted |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
72 | - { |
|
73 | - return number_format( |
|
74 | - $value_on_field_to_be_outputted, |
|
75 | - $this->currency->dec_plc, |
|
76 | - $this->currency->dec_mrk, |
|
77 | - $this->currency->thsnds |
|
78 | - ); |
|
79 | - } |
|
65 | + /** |
|
66 | + * Returns the number formatted according to local custom (set by the country of the blog). |
|
67 | + * |
|
68 | + * @param float $value_on_field_to_be_outputted |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
72 | + { |
|
73 | + return number_format( |
|
74 | + $value_on_field_to_be_outputted, |
|
75 | + $this->currency->dec_plc, |
|
76 | + $this->currency->dec_mrk, |
|
77 | + $this->currency->thsnds |
|
78 | + ); |
|
79 | + } |
|
80 | 80 | |
81 | - public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
82 | - { |
|
83 | - return floatval($value_found_in_db_for_model_object); |
|
84 | - } |
|
81 | + public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
82 | + { |
|
83 | + return floatval($value_found_in_db_for_model_object); |
|
84 | + } |
|
85 | 85 | } |
@@ -29,643 +29,643 @@ |
||
29 | 29 | */ |
30 | 30 | abstract class FormHandler implements FormHandlerInterface |
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' => ' ', |
|
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' => ' ', |
|
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 InvalidInterfaceException |
|
577 | - * @throws 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 InvalidInterfaceException |
|
640 | - * @throws 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); |
|
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' => ' ', |
|
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' => ' ', |
|
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 InvalidInterfaceException |
|
577 | + * @throws 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 InvalidInterfaceException |
|
640 | + * @throws 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 | 651 | if (! $this->form()->is_valid()) { |
652 | 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 | - } |
|
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 | } |
@@ -171,7 +171,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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' => ' ', |
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 |
||
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 |
||
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' => ' ', |
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 |
||
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 |
||
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( |
@@ -24,9 +24,9 @@ |
||
24 | 24 | ] |
25 | 25 | ) |
26 | 26 | ); |
27 | - if (! is_array($answer_options) || empty($answer_options)) { |
|
27 | + if ( ! is_array($answer_options) || empty($answer_options)) { |
|
28 | 28 | $answer_options = [ |
29 | - EE_Switch_Input::OPTION_ON => esc_html__( 'enabled', 'event_espresso'), |
|
29 | + EE_Switch_Input::OPTION_ON => esc_html__('enabled', 'event_espresso'), |
|
30 | 30 | EE_Switch_Input::OPTION_OFF => esc_html__('disabled', 'event_espresso'), |
31 | 31 | ]; |
32 | 32 | } |
@@ -13,16 +13,16 @@ |
||
13 | 13 | */ |
14 | 14 | class EE_Select_Input extends EE_Form_Input_With_Options_Base |
15 | 15 | { |
16 | - /** |
|
17 | - * @param array $answer_options |
|
18 | - * @param array $input_settings |
|
19 | - */ |
|
20 | - public function __construct($answer_options, $input_settings = array()) |
|
21 | - { |
|
22 | - $this->_set_display_strategy(new EE_Select_Display_Strategy($answer_options)); |
|
23 | - $this->_add_validation_strategy( |
|
24 | - new EE_Enum_Validation_Strategy($input_settings['validation_error_message'] ?? null) |
|
25 | - ); |
|
26 | - parent::__construct($answer_options, $input_settings); |
|
27 | - } |
|
16 | + /** |
|
17 | + * @param array $answer_options |
|
18 | + * @param array $input_settings |
|
19 | + */ |
|
20 | + public function __construct($answer_options, $input_settings = array()) |
|
21 | + { |
|
22 | + $this->_set_display_strategy(new EE_Select_Display_Strategy($answer_options)); |
|
23 | + $this->_add_validation_strategy( |
|
24 | + new EE_Enum_Validation_Strategy($input_settings['validation_error_message'] ?? null) |
|
25 | + ); |
|
26 | + parent::__construct($answer_options, $input_settings); |
|
27 | + } |
|
28 | 28 | } |
@@ -11,17 +11,17 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Radio_Button_Input extends EE_Form_Input_With_Options_Base |
13 | 13 | { |
14 | - /** |
|
15 | - * @param array $answer_options |
|
16 | - * @param array $input_settings |
|
17 | - */ |
|
18 | - public function __construct($answer_options, $input_settings = array()) |
|
19 | - { |
|
20 | - $this->_set_display_strategy(new EE_Radio_Button_Display_Strategy()); |
|
21 | - $this->_add_validation_strategy( |
|
22 | - new EE_Enum_Validation_Strategy($input_settings['validation_error_message'] ?? null) |
|
23 | - ); |
|
24 | - $this->_multiple_selections = false; |
|
25 | - parent::__construct($answer_options, $input_settings); |
|
26 | - } |
|
14 | + /** |
|
15 | + * @param array $answer_options |
|
16 | + * @param array $input_settings |
|
17 | + */ |
|
18 | + public function __construct($answer_options, $input_settings = array()) |
|
19 | + { |
|
20 | + $this->_set_display_strategy(new EE_Radio_Button_Display_Strategy()); |
|
21 | + $this->_add_validation_strategy( |
|
22 | + new EE_Enum_Validation_Strategy($input_settings['validation_error_message'] ?? null) |
|
23 | + ); |
|
24 | + $this->_multiple_selections = false; |
|
25 | + parent::__construct($answer_options, $input_settings); |
|
26 | + } |
|
27 | 27 | } |