@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | public function form($for_display = false) |
| 172 | 172 | { |
| 173 | - if (! $this->formIsValid()) { |
|
| 173 | + if ( ! $this->formIsValid()) { |
|
| 174 | 174 | return null; |
| 175 | 175 | } |
| 176 | 176 | if ($for_display) { |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | */ |
| 273 | 273 | public function setFormName($form_name) |
| 274 | 274 | { |
| 275 | - if (! is_string($form_name)) { |
|
| 275 | + if ( ! is_string($form_name)) { |
|
| 276 | 276 | throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
| 277 | 277 | } |
| 278 | 278 | $this->form_name = $form_name; |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | */ |
| 297 | 297 | public function setAdminName($admin_name) |
| 298 | 298 | { |
| 299 | - if (! is_string($admin_name)) { |
|
| 299 | + if ( ! is_string($admin_name)) { |
|
| 300 | 300 | throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
| 301 | 301 | } |
| 302 | 302 | $this->admin_name = $admin_name; |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | */ |
| 321 | 321 | public function setSlug($slug) |
| 322 | 322 | { |
| 323 | - if (! is_string($slug)) { |
|
| 323 | + if ( ! is_string($slug)) { |
|
| 324 | 324 | throw new InvalidDataTypeException('$slug', $slug, 'string'); |
| 325 | 325 | } |
| 326 | 326 | $this->slug = $slug; |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | */ |
| 344 | 344 | public function setSubmitBtnText($submit_btn_text) |
| 345 | 345 | { |
| 346 | - if (! is_string($submit_btn_text)) { |
|
| 346 | + if ( ! is_string($submit_btn_text)) { |
|
| 347 | 347 | throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
| 348 | 348 | } |
| 349 | 349 | if (empty($submit_btn_text)) { |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | */ |
| 373 | 373 | public function setFormAction($form_action) |
| 374 | 374 | { |
| 375 | - if (! is_string($form_action)) { |
|
| 375 | + if ( ! is_string($form_action)) { |
|
| 376 | 376 | throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
| 377 | 377 | } |
| 378 | 378 | $this->form_action = $form_action; |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | */ |
| 418 | 418 | public function setFormConfig($form_config) |
| 419 | 419 | { |
| 420 | - if (! in_array( |
|
| 420 | + if ( ! in_array( |
|
| 421 | 421 | $form_config, |
| 422 | 422 | array( |
| 423 | 423 | FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
@@ -490,11 +490,11 @@ discard block |
||
| 490 | 490 | $text = ! empty($text) ? $text : $this->submitBtnText(); |
| 491 | 491 | return new EE_Submit_Input( |
| 492 | 492 | array( |
| 493 | - 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
| 494 | - 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
| 493 | + 'html_name' => 'ee-form-submit-'.$this->slug(), |
|
| 494 | + 'html_id' => 'ee-form-submit-'.$this->slug(), |
|
| 495 | 495 | 'html_class' => 'ee-form-submit', |
| 496 | 496 | 'html_label' => ' ', |
| 497 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
| 497 | + 'other_html_attributes' => ' rel="'.$this->slug().'"', |
|
| 498 | 498 | 'default' => $text, |
| 499 | 499 | ) |
| 500 | 500 | ); |
@@ -510,11 +510,11 @@ discard block |
||
| 510 | 510 | */ |
| 511 | 511 | public function appendSubmitButton($text = '') |
| 512 | 512 | { |
| 513 | - if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
| 513 | + if ($this->form->subsection_exists($this->slug().'-submit-btn')) { |
|
| 514 | 514 | return; |
| 515 | 515 | } |
| 516 | 516 | $this->form->add_subsections( |
| 517 | - array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
| 517 | + array($this->slug().'-submit-btn' => $this->generateSubmitButton($text)), |
|
| 518 | 518 | null, |
| 519 | 519 | false |
| 520 | 520 | ); |
@@ -531,11 +531,11 @@ discard block |
||
| 531 | 531 | { |
| 532 | 532 | $cancel_button = new EE_Submit_Input( |
| 533 | 533 | array( |
| 534 | - 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
| 535 | - 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
| 534 | + 'html_name' => 'ee-form-submit-'.$this->slug(), // YES! Same name as submit !!! |
|
| 535 | + 'html_id' => 'ee-cancel-form-'.$this->slug(), |
|
| 536 | 536 | 'html_class' => 'ee-cancel-form', |
| 537 | 537 | 'html_label' => ' ', |
| 538 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
| 538 | + 'other_html_attributes' => ' rel="'.$this->slug().'"', |
|
| 539 | 539 | 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
| 540 | 540 | ) |
| 541 | 541 | ); |
@@ -555,7 +555,7 @@ discard block |
||
| 555 | 555 | $this->form->add_subsections( |
| 556 | 556 | array( |
| 557 | 557 | 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
| 558 | - EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
| 558 | + EEH_HTML::div('', '', 'clear-float').EEH_HTML::divx() |
|
| 559 | 559 | ), |
| 560 | 560 | ), |
| 561 | 561 | null, |
@@ -616,11 +616,11 @@ discard block |
||
| 616 | 616 | */ |
| 617 | 617 | public function process($submitted_form_data = array()) |
| 618 | 618 | { |
| 619 | - if (! $this->form()->was_submitted($submitted_form_data)) { |
|
| 619 | + if ( ! $this->form()->was_submitted($submitted_form_data)) { |
|
| 620 | 620 | throw new InvalidFormSubmissionException($this->form_name); |
| 621 | 621 | } |
| 622 | 622 | $this->form(true)->receive_form_submission($submitted_form_data); |
| 623 | - if (! $this->form()->is_valid()) { |
|
| 623 | + if ( ! $this->form()->is_valid()) { |
|
| 624 | 624 | throw new InvalidFormSubmissionException( |
| 625 | 625 | $this->form_name, |
| 626 | 626 | sprintf( |
@@ -28,616 +28,616 @@ |
||
| 28 | 28 | abstract class FormHandler implements FormHandlerInterface |
| 29 | 29 | { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * will add opening and closing HTML form tags as well as a submit button |
|
| 33 | - */ |
|
| 34 | - const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit'; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * will add opening and closing HTML form tags but NOT a submit button |
|
| 38 | - */ |
|
| 39 | - const ADD_FORM_TAGS_ONLY = 'add_form_tags_only'; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * will NOT add opening and closing HTML form tags but will add a submit button |
|
| 43 | - */ |
|
| 44 | - const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only'; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * will NOT add opening and closing HTML form tags NOR a submit button |
|
| 48 | - */ |
|
| 49 | - const DO_NOT_SETUP_FORM = 'do_not_setup_form'; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * if set to false, then this form has no displayable content, |
|
| 53 | - * and will only be used for processing data sent passed via GET or POST |
|
| 54 | - * defaults to true ( ie: form has displayable content ) |
|
| 55 | - * |
|
| 56 | - * @var boolean $displayable |
|
| 57 | - */ |
|
| 58 | - private $displayable = true; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @var string $form_name |
|
| 62 | - */ |
|
| 63 | - private $form_name; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @var string $admin_name |
|
| 67 | - */ |
|
| 68 | - private $admin_name; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @var string $slug |
|
| 72 | - */ |
|
| 73 | - private $slug; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @var string $submit_btn_text |
|
| 77 | - */ |
|
| 78 | - private $submit_btn_text; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @var string $form_action |
|
| 82 | - */ |
|
| 83 | - private $form_action; |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * form params in key value pairs |
|
| 87 | - * can be added to form action URL or as hidden inputs |
|
| 88 | - * |
|
| 89 | - * @var array $form_args |
|
| 90 | - */ |
|
| 91 | - private $form_args = array(); |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * value of one of the string constant above |
|
| 95 | - * |
|
| 96 | - * @var string $form_config |
|
| 97 | - */ |
|
| 98 | - private $form_config; |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * whether or not the form was determined to be invalid |
|
| 102 | - * |
|
| 103 | - * @var boolean $form_has_errors |
|
| 104 | - */ |
|
| 105 | - private $form_has_errors; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * the absolute top level form section being used on the page |
|
| 109 | - * |
|
| 110 | - * @var EE_Form_Section_Proper $form |
|
| 111 | - */ |
|
| 112 | - private $form; |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @var EE_Registry $registry |
|
| 116 | - */ |
|
| 117 | - protected $registry; |
|
| 118 | - |
|
| 119 | - // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
| 120 | - /** |
|
| 121 | - * Form constructor. |
|
| 122 | - * |
|
| 123 | - * @param string $form_name |
|
| 124 | - * @param string $admin_name |
|
| 125 | - * @param string $slug |
|
| 126 | - * @param string $form_action |
|
| 127 | - * @param string $form_config |
|
| 128 | - * @param EE_Registry $registry |
|
| 129 | - * @throws InvalidDataTypeException |
|
| 130 | - * @throws DomainException |
|
| 131 | - * @throws InvalidArgumentException |
|
| 132 | - */ |
|
| 133 | - public function __construct( |
|
| 134 | - $form_name, |
|
| 135 | - $admin_name, |
|
| 136 | - $slug, |
|
| 137 | - $form_action = '', |
|
| 138 | - $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 139 | - EE_Registry $registry |
|
| 140 | - ) { |
|
| 141 | - $this->setFormName($form_name); |
|
| 142 | - $this->setAdminName($admin_name); |
|
| 143 | - $this->setSlug($slug); |
|
| 144 | - $this->setFormAction($form_action); |
|
| 145 | - $this->setFormConfig($form_config); |
|
| 146 | - $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso')); |
|
| 147 | - $this->registry = $registry; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @return array |
|
| 153 | - */ |
|
| 154 | - public static function getFormConfigConstants() |
|
| 155 | - { |
|
| 156 | - return array( |
|
| 157 | - FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 158 | - FormHandler::ADD_FORM_TAGS_ONLY, |
|
| 159 | - FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
| 160 | - FormHandler::DO_NOT_SETUP_FORM, |
|
| 161 | - ); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * @param bool $for_display |
|
| 167 | - * @return EE_Form_Section_Proper |
|
| 168 | - * @throws EE_Error |
|
| 169 | - * @throws LogicException |
|
| 170 | - */ |
|
| 171 | - public function form($for_display = false) |
|
| 172 | - { |
|
| 173 | - if (! $this->formIsValid()) { |
|
| 174 | - return null; |
|
| 175 | - } |
|
| 176 | - if ($for_display) { |
|
| 177 | - $form_config = $this->formConfig(); |
|
| 178 | - if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 179 | - || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY |
|
| 180 | - ) { |
|
| 181 | - $this->appendSubmitButton(); |
|
| 182 | - $this->clearFormButtonFloats(); |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - return $this->form; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * @return boolean |
|
| 191 | - * @throws LogicException |
|
| 192 | - */ |
|
| 193 | - public function formIsValid() |
|
| 194 | - { |
|
| 195 | - if ($this->form instanceof EE_Form_Section_Proper) { |
|
| 196 | - return true; |
|
| 197 | - } |
|
| 198 | - $form = apply_filters( |
|
| 199 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
|
| 200 | - $this->generate(), |
|
| 201 | - $this |
|
| 202 | - ); |
|
| 203 | - if ($this->verifyForm($form)) { |
|
| 204 | - $this->setForm($form); |
|
| 205 | - } |
|
| 206 | - return true; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * @param EE_Form_Section_Proper|null $form |
|
| 212 | - * @return bool |
|
| 213 | - * @throws LogicException |
|
| 214 | - */ |
|
| 215 | - public function verifyForm(EE_Form_Section_Proper $form = null) |
|
| 216 | - { |
|
| 217 | - $form = $form !== null ? $form : $this->form; |
|
| 218 | - if ($form instanceof EE_Form_Section_Proper) { |
|
| 219 | - return true; |
|
| 220 | - } |
|
| 221 | - throw new LogicException( |
|
| 222 | - sprintf( |
|
| 223 | - esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'), |
|
| 224 | - $this->form_name, |
|
| 225 | - var_export($form, true) |
|
| 226 | - ) |
|
| 227 | - ); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * @param EE_Form_Section_Proper $form |
|
| 233 | - */ |
|
| 234 | - public function setForm(EE_Form_Section_Proper $form) |
|
| 235 | - { |
|
| 236 | - $this->form = $form; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * @return boolean |
|
| 242 | - */ |
|
| 243 | - public function displayable() |
|
| 244 | - { |
|
| 245 | - return $this->displayable; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * @param boolean $displayable |
|
| 251 | - */ |
|
| 252 | - public function setDisplayable($displayable = false) |
|
| 253 | - { |
|
| 254 | - $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * a public name for the form that can be displayed on the frontend of a site |
|
| 260 | - * |
|
| 261 | - * @return string |
|
| 262 | - */ |
|
| 263 | - public function formName() |
|
| 264 | - { |
|
| 265 | - return $this->form_name; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * @param string $form_name |
|
| 271 | - * @throws InvalidDataTypeException |
|
| 272 | - */ |
|
| 273 | - public function setFormName($form_name) |
|
| 274 | - { |
|
| 275 | - if (! is_string($form_name)) { |
|
| 276 | - throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
|
| 277 | - } |
|
| 278 | - $this->form_name = $form_name; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * a public name for the form that can be displayed, but only in the admin |
|
| 284 | - * |
|
| 285 | - * @return string |
|
| 286 | - */ |
|
| 287 | - public function adminName() |
|
| 288 | - { |
|
| 289 | - return $this->admin_name; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * @param string $admin_name |
|
| 295 | - * @throws InvalidDataTypeException |
|
| 296 | - */ |
|
| 297 | - public function setAdminName($admin_name) |
|
| 298 | - { |
|
| 299 | - if (! is_string($admin_name)) { |
|
| 300 | - throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
| 301 | - } |
|
| 302 | - $this->admin_name = $admin_name; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * a URL friendly string that can be used for identifying the form |
|
| 308 | - * |
|
| 309 | - * @return string |
|
| 310 | - */ |
|
| 311 | - public function slug() |
|
| 312 | - { |
|
| 313 | - return $this->slug; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * @param string $slug |
|
| 319 | - * @throws InvalidDataTypeException |
|
| 320 | - */ |
|
| 321 | - public function setSlug($slug) |
|
| 322 | - { |
|
| 323 | - if (! is_string($slug)) { |
|
| 324 | - throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
| 325 | - } |
|
| 326 | - $this->slug = $slug; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * @return string |
|
| 332 | - */ |
|
| 333 | - public function submitBtnText() |
|
| 334 | - { |
|
| 335 | - return $this->submit_btn_text; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * @param string $submit_btn_text |
|
| 341 | - * @throws InvalidDataTypeException |
|
| 342 | - * @throws InvalidArgumentException |
|
| 343 | - */ |
|
| 344 | - public function setSubmitBtnText($submit_btn_text) |
|
| 345 | - { |
|
| 346 | - if (! is_string($submit_btn_text)) { |
|
| 347 | - throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
| 348 | - } |
|
| 349 | - if (empty($submit_btn_text)) { |
|
| 350 | - throw new InvalidArgumentException( |
|
| 351 | - esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
| 352 | - ); |
|
| 353 | - } |
|
| 354 | - $this->submit_btn_text = $submit_btn_text; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * @return string |
|
| 360 | - */ |
|
| 361 | - public function formAction() |
|
| 362 | - { |
|
| 363 | - return ! empty($this->form_args) |
|
| 364 | - ? add_query_arg($this->form_args, $this->form_action) |
|
| 365 | - : $this->form_action; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * @param string $form_action |
|
| 371 | - * @throws InvalidDataTypeException |
|
| 372 | - */ |
|
| 373 | - public function setFormAction($form_action) |
|
| 374 | - { |
|
| 375 | - if (! is_string($form_action)) { |
|
| 376 | - throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
| 377 | - } |
|
| 378 | - $this->form_action = $form_action; |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * @param array $form_args |
|
| 384 | - * @throws InvalidDataTypeException |
|
| 385 | - * @throws InvalidArgumentException |
|
| 386 | - */ |
|
| 387 | - public function addFormActionArgs($form_args = array()) |
|
| 388 | - { |
|
| 389 | - if (is_object($form_args)) { |
|
| 390 | - throw new InvalidDataTypeException( |
|
| 391 | - '$form_args', |
|
| 392 | - $form_args, |
|
| 393 | - 'anything other than an object was expected.' |
|
| 394 | - ); |
|
| 395 | - } |
|
| 396 | - if (empty($form_args)) { |
|
| 397 | - throw new InvalidArgumentException( |
|
| 398 | - esc_html__('The redirect arguments can not be an empty array.', 'event_espresso') |
|
| 399 | - ); |
|
| 400 | - } |
|
| 401 | - $this->form_args = array_merge($this->form_args, $form_args); |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * @return string |
|
| 407 | - */ |
|
| 408 | - public function formConfig() |
|
| 409 | - { |
|
| 410 | - return $this->form_config; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * @param string $form_config |
|
| 416 | - * @throws DomainException |
|
| 417 | - */ |
|
| 418 | - public function setFormConfig($form_config) |
|
| 419 | - { |
|
| 420 | - if (! in_array( |
|
| 421 | - $form_config, |
|
| 422 | - array( |
|
| 423 | - FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 424 | - FormHandler::ADD_FORM_TAGS_ONLY, |
|
| 425 | - FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
| 426 | - FormHandler::DO_NOT_SETUP_FORM, |
|
| 427 | - ), |
|
| 428 | - true |
|
| 429 | - ) |
|
| 430 | - ) { |
|
| 431 | - throw new DomainException( |
|
| 432 | - sprintf( |
|
| 433 | - esc_html__( |
|
| 434 | - '"%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', |
|
| 435 | - 'event_espresso' |
|
| 436 | - ), |
|
| 437 | - $form_config |
|
| 438 | - ) |
|
| 439 | - ); |
|
| 440 | - } |
|
| 441 | - $this->form_config = $form_config; |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * called after the form is instantiated |
|
| 447 | - * and used for performing any logic that needs to occur early |
|
| 448 | - * before any of the other methods are called. |
|
| 449 | - * returns true if everything is ok to proceed, |
|
| 450 | - * and false if no further form logic should be implemented |
|
| 451 | - * |
|
| 452 | - * @return boolean |
|
| 453 | - */ |
|
| 454 | - public function initialize() |
|
| 455 | - { |
|
| 456 | - $this->form_has_errors = EE_Error::has_error(true); |
|
| 457 | - return true; |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - |
|
| 461 | - /** |
|
| 462 | - * used for setting up css and js |
|
| 463 | - * |
|
| 464 | - * @return void |
|
| 465 | - * @throws LogicException |
|
| 466 | - * @throws EE_Error |
|
| 467 | - */ |
|
| 468 | - public function enqueueStylesAndScripts() |
|
| 469 | - { |
|
| 470 | - $this->form()->enqueue_js(); |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - |
|
| 474 | - /** |
|
| 475 | - * creates and returns the actual form |
|
| 476 | - * |
|
| 477 | - * @return EE_Form_Section_Proper |
|
| 478 | - */ |
|
| 479 | - abstract public function generate(); |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * creates and returns an EE_Submit_Input labeled "Submit" |
|
| 484 | - * |
|
| 485 | - * @param string $text |
|
| 486 | - * @return EE_Submit_Input |
|
| 487 | - */ |
|
| 488 | - public function generateSubmitButton($text = '') |
|
| 489 | - { |
|
| 490 | - $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
| 491 | - return new EE_Submit_Input( |
|
| 492 | - array( |
|
| 493 | - 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
| 494 | - 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
| 495 | - 'html_class' => 'ee-form-submit', |
|
| 496 | - 'html_label' => ' ', |
|
| 497 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
| 498 | - 'default' => $text, |
|
| 499 | - ) |
|
| 500 | - ); |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - |
|
| 504 | - /** |
|
| 505 | - * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
| 506 | - * |
|
| 507 | - * @param string $text |
|
| 508 | - * @return void |
|
| 509 | - * @throws EE_Error |
|
| 510 | - */ |
|
| 511 | - public function appendSubmitButton($text = '') |
|
| 512 | - { |
|
| 513 | - if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
| 514 | - return; |
|
| 515 | - } |
|
| 516 | - $this->form->add_subsections( |
|
| 517 | - array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
| 518 | - null, |
|
| 519 | - false |
|
| 520 | - ); |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - |
|
| 524 | - /** |
|
| 525 | - * creates and returns an EE_Submit_Input labeled "Cancel" |
|
| 526 | - * |
|
| 527 | - * @param string $text |
|
| 528 | - * @return EE_Submit_Input |
|
| 529 | - */ |
|
| 530 | - public function generateCancelButton($text = '') |
|
| 531 | - { |
|
| 532 | - $cancel_button = new EE_Submit_Input( |
|
| 533 | - array( |
|
| 534 | - 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
| 535 | - 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
| 536 | - 'html_class' => 'ee-cancel-form', |
|
| 537 | - 'html_label' => ' ', |
|
| 538 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
| 539 | - 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
|
| 540 | - ) |
|
| 541 | - ); |
|
| 542 | - $cancel_button->set_button_css_attributes(false); |
|
| 543 | - return $cancel_button; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - |
|
| 547 | - /** |
|
| 548 | - * appends a float clearing div onto end of form |
|
| 549 | - * |
|
| 550 | - * @return void |
|
| 551 | - * @throws EE_Error |
|
| 552 | - */ |
|
| 553 | - public function clearFormButtonFloats() |
|
| 554 | - { |
|
| 555 | - $this->form->add_subsections( |
|
| 556 | - array( |
|
| 557 | - 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
|
| 558 | - EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
| 559 | - ), |
|
| 560 | - ), |
|
| 561 | - null, |
|
| 562 | - false |
|
| 563 | - ); |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - |
|
| 567 | - /** |
|
| 568 | - * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
| 569 | - * returns a string of HTML that can be directly echoed in a template |
|
| 570 | - * |
|
| 571 | - * @return string |
|
| 572 | - * @throws \InvalidArgumentException |
|
| 573 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 574 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 575 | - * @throws LogicException |
|
| 576 | - * @throws EE_Error |
|
| 577 | - */ |
|
| 578 | - public function display() |
|
| 579 | - { |
|
| 580 | - $form_html = apply_filters( |
|
| 581 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
|
| 582 | - '' |
|
| 583 | - ); |
|
| 584 | - $form_config = $this->formConfig(); |
|
| 585 | - if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 586 | - || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
| 587 | - ) { |
|
| 588 | - $form_html .= $this->form()->form_open($this->formAction()); |
|
| 589 | - } |
|
| 590 | - $form_html .= $this->form(true)->get_html(); |
|
| 591 | - if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 592 | - || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
| 593 | - ) { |
|
| 594 | - $form_html .= $this->form()->form_close(); |
|
| 595 | - } |
|
| 596 | - $form_html .= apply_filters( |
|
| 597 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form', |
|
| 598 | - '' |
|
| 599 | - ); |
|
| 600 | - return $form_html; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - |
|
| 604 | - /** |
|
| 605 | - * handles processing the form submission |
|
| 606 | - * returns true or false depending on whether the form was processed successfully or not |
|
| 607 | - * |
|
| 608 | - * @param array $submitted_form_data |
|
| 609 | - * @return array |
|
| 610 | - * @throws \InvalidArgumentException |
|
| 611 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 612 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 613 | - * @throws EE_Error |
|
| 614 | - * @throws LogicException |
|
| 615 | - * @throws InvalidFormSubmissionException |
|
| 616 | - */ |
|
| 617 | - public function process($submitted_form_data = array()) |
|
| 618 | - { |
|
| 619 | - if (! $this->form()->was_submitted($submitted_form_data)) { |
|
| 620 | - throw new InvalidFormSubmissionException($this->form_name); |
|
| 621 | - } |
|
| 622 | - $this->form(true)->receive_form_submission($submitted_form_data); |
|
| 623 | - if (! $this->form()->is_valid()) { |
|
| 624 | - throw new InvalidFormSubmissionException( |
|
| 625 | - $this->form_name, |
|
| 626 | - sprintf( |
|
| 627 | - esc_html__( |
|
| 628 | - 'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s', |
|
| 629 | - 'event_espresso' |
|
| 630 | - ), |
|
| 631 | - $this->form_name, |
|
| 632 | - '<br />', |
|
| 633 | - implode('<br />', $this->form()->get_validation_errors_accumulated()) |
|
| 634 | - ) |
|
| 635 | - ); |
|
| 636 | - } |
|
| 637 | - return apply_filters( |
|
| 638 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data', |
|
| 639 | - $this->form()->valid_data(), |
|
| 640 | - $this |
|
| 641 | - ); |
|
| 642 | - } |
|
| 31 | + /** |
|
| 32 | + * will add opening and closing HTML form tags as well as a submit button |
|
| 33 | + */ |
|
| 34 | + const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit'; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * will add opening and closing HTML form tags but NOT a submit button |
|
| 38 | + */ |
|
| 39 | + const ADD_FORM_TAGS_ONLY = 'add_form_tags_only'; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * will NOT add opening and closing HTML form tags but will add a submit button |
|
| 43 | + */ |
|
| 44 | + const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only'; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * will NOT add opening and closing HTML form tags NOR a submit button |
|
| 48 | + */ |
|
| 49 | + const DO_NOT_SETUP_FORM = 'do_not_setup_form'; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * if set to false, then this form has no displayable content, |
|
| 53 | + * and will only be used for processing data sent passed via GET or POST |
|
| 54 | + * defaults to true ( ie: form has displayable content ) |
|
| 55 | + * |
|
| 56 | + * @var boolean $displayable |
|
| 57 | + */ |
|
| 58 | + private $displayable = true; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @var string $form_name |
|
| 62 | + */ |
|
| 63 | + private $form_name; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @var string $admin_name |
|
| 67 | + */ |
|
| 68 | + private $admin_name; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @var string $slug |
|
| 72 | + */ |
|
| 73 | + private $slug; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @var string $submit_btn_text |
|
| 77 | + */ |
|
| 78 | + private $submit_btn_text; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @var string $form_action |
|
| 82 | + */ |
|
| 83 | + private $form_action; |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * form params in key value pairs |
|
| 87 | + * can be added to form action URL or as hidden inputs |
|
| 88 | + * |
|
| 89 | + * @var array $form_args |
|
| 90 | + */ |
|
| 91 | + private $form_args = array(); |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * value of one of the string constant above |
|
| 95 | + * |
|
| 96 | + * @var string $form_config |
|
| 97 | + */ |
|
| 98 | + private $form_config; |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * whether or not the form was determined to be invalid |
|
| 102 | + * |
|
| 103 | + * @var boolean $form_has_errors |
|
| 104 | + */ |
|
| 105 | + private $form_has_errors; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * the absolute top level form section being used on the page |
|
| 109 | + * |
|
| 110 | + * @var EE_Form_Section_Proper $form |
|
| 111 | + */ |
|
| 112 | + private $form; |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @var EE_Registry $registry |
|
| 116 | + */ |
|
| 117 | + protected $registry; |
|
| 118 | + |
|
| 119 | + // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
| 120 | + /** |
|
| 121 | + * Form constructor. |
|
| 122 | + * |
|
| 123 | + * @param string $form_name |
|
| 124 | + * @param string $admin_name |
|
| 125 | + * @param string $slug |
|
| 126 | + * @param string $form_action |
|
| 127 | + * @param string $form_config |
|
| 128 | + * @param EE_Registry $registry |
|
| 129 | + * @throws InvalidDataTypeException |
|
| 130 | + * @throws DomainException |
|
| 131 | + * @throws InvalidArgumentException |
|
| 132 | + */ |
|
| 133 | + public function __construct( |
|
| 134 | + $form_name, |
|
| 135 | + $admin_name, |
|
| 136 | + $slug, |
|
| 137 | + $form_action = '', |
|
| 138 | + $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 139 | + EE_Registry $registry |
|
| 140 | + ) { |
|
| 141 | + $this->setFormName($form_name); |
|
| 142 | + $this->setAdminName($admin_name); |
|
| 143 | + $this->setSlug($slug); |
|
| 144 | + $this->setFormAction($form_action); |
|
| 145 | + $this->setFormConfig($form_config); |
|
| 146 | + $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso')); |
|
| 147 | + $this->registry = $registry; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @return array |
|
| 153 | + */ |
|
| 154 | + public static function getFormConfigConstants() |
|
| 155 | + { |
|
| 156 | + return array( |
|
| 157 | + FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 158 | + FormHandler::ADD_FORM_TAGS_ONLY, |
|
| 159 | + FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
| 160 | + FormHandler::DO_NOT_SETUP_FORM, |
|
| 161 | + ); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * @param bool $for_display |
|
| 167 | + * @return EE_Form_Section_Proper |
|
| 168 | + * @throws EE_Error |
|
| 169 | + * @throws LogicException |
|
| 170 | + */ |
|
| 171 | + public function form($for_display = false) |
|
| 172 | + { |
|
| 173 | + if (! $this->formIsValid()) { |
|
| 174 | + return null; |
|
| 175 | + } |
|
| 176 | + if ($for_display) { |
|
| 177 | + $form_config = $this->formConfig(); |
|
| 178 | + if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 179 | + || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY |
|
| 180 | + ) { |
|
| 181 | + $this->appendSubmitButton(); |
|
| 182 | + $this->clearFormButtonFloats(); |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + return $this->form; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * @return boolean |
|
| 191 | + * @throws LogicException |
|
| 192 | + */ |
|
| 193 | + public function formIsValid() |
|
| 194 | + { |
|
| 195 | + if ($this->form instanceof EE_Form_Section_Proper) { |
|
| 196 | + return true; |
|
| 197 | + } |
|
| 198 | + $form = apply_filters( |
|
| 199 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
|
| 200 | + $this->generate(), |
|
| 201 | + $this |
|
| 202 | + ); |
|
| 203 | + if ($this->verifyForm($form)) { |
|
| 204 | + $this->setForm($form); |
|
| 205 | + } |
|
| 206 | + return true; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * @param EE_Form_Section_Proper|null $form |
|
| 212 | + * @return bool |
|
| 213 | + * @throws LogicException |
|
| 214 | + */ |
|
| 215 | + public function verifyForm(EE_Form_Section_Proper $form = null) |
|
| 216 | + { |
|
| 217 | + $form = $form !== null ? $form : $this->form; |
|
| 218 | + if ($form instanceof EE_Form_Section_Proper) { |
|
| 219 | + return true; |
|
| 220 | + } |
|
| 221 | + throw new LogicException( |
|
| 222 | + sprintf( |
|
| 223 | + esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'), |
|
| 224 | + $this->form_name, |
|
| 225 | + var_export($form, true) |
|
| 226 | + ) |
|
| 227 | + ); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * @param EE_Form_Section_Proper $form |
|
| 233 | + */ |
|
| 234 | + public function setForm(EE_Form_Section_Proper $form) |
|
| 235 | + { |
|
| 236 | + $this->form = $form; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * @return boolean |
|
| 242 | + */ |
|
| 243 | + public function displayable() |
|
| 244 | + { |
|
| 245 | + return $this->displayable; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * @param boolean $displayable |
|
| 251 | + */ |
|
| 252 | + public function setDisplayable($displayable = false) |
|
| 253 | + { |
|
| 254 | + $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * a public name for the form that can be displayed on the frontend of a site |
|
| 260 | + * |
|
| 261 | + * @return string |
|
| 262 | + */ |
|
| 263 | + public function formName() |
|
| 264 | + { |
|
| 265 | + return $this->form_name; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * @param string $form_name |
|
| 271 | + * @throws InvalidDataTypeException |
|
| 272 | + */ |
|
| 273 | + public function setFormName($form_name) |
|
| 274 | + { |
|
| 275 | + if (! is_string($form_name)) { |
|
| 276 | + throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
|
| 277 | + } |
|
| 278 | + $this->form_name = $form_name; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * a public name for the form that can be displayed, but only in the admin |
|
| 284 | + * |
|
| 285 | + * @return string |
|
| 286 | + */ |
|
| 287 | + public function adminName() |
|
| 288 | + { |
|
| 289 | + return $this->admin_name; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * @param string $admin_name |
|
| 295 | + * @throws InvalidDataTypeException |
|
| 296 | + */ |
|
| 297 | + public function setAdminName($admin_name) |
|
| 298 | + { |
|
| 299 | + if (! is_string($admin_name)) { |
|
| 300 | + throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
| 301 | + } |
|
| 302 | + $this->admin_name = $admin_name; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * a URL friendly string that can be used for identifying the form |
|
| 308 | + * |
|
| 309 | + * @return string |
|
| 310 | + */ |
|
| 311 | + public function slug() |
|
| 312 | + { |
|
| 313 | + return $this->slug; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * @param string $slug |
|
| 319 | + * @throws InvalidDataTypeException |
|
| 320 | + */ |
|
| 321 | + public function setSlug($slug) |
|
| 322 | + { |
|
| 323 | + if (! is_string($slug)) { |
|
| 324 | + throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
| 325 | + } |
|
| 326 | + $this->slug = $slug; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * @return string |
|
| 332 | + */ |
|
| 333 | + public function submitBtnText() |
|
| 334 | + { |
|
| 335 | + return $this->submit_btn_text; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * @param string $submit_btn_text |
|
| 341 | + * @throws InvalidDataTypeException |
|
| 342 | + * @throws InvalidArgumentException |
|
| 343 | + */ |
|
| 344 | + public function setSubmitBtnText($submit_btn_text) |
|
| 345 | + { |
|
| 346 | + if (! is_string($submit_btn_text)) { |
|
| 347 | + throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
| 348 | + } |
|
| 349 | + if (empty($submit_btn_text)) { |
|
| 350 | + throw new InvalidArgumentException( |
|
| 351 | + esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
| 352 | + ); |
|
| 353 | + } |
|
| 354 | + $this->submit_btn_text = $submit_btn_text; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * @return string |
|
| 360 | + */ |
|
| 361 | + public function formAction() |
|
| 362 | + { |
|
| 363 | + return ! empty($this->form_args) |
|
| 364 | + ? add_query_arg($this->form_args, $this->form_action) |
|
| 365 | + : $this->form_action; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * @param string $form_action |
|
| 371 | + * @throws InvalidDataTypeException |
|
| 372 | + */ |
|
| 373 | + public function setFormAction($form_action) |
|
| 374 | + { |
|
| 375 | + if (! is_string($form_action)) { |
|
| 376 | + throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
| 377 | + } |
|
| 378 | + $this->form_action = $form_action; |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * @param array $form_args |
|
| 384 | + * @throws InvalidDataTypeException |
|
| 385 | + * @throws InvalidArgumentException |
|
| 386 | + */ |
|
| 387 | + public function addFormActionArgs($form_args = array()) |
|
| 388 | + { |
|
| 389 | + if (is_object($form_args)) { |
|
| 390 | + throw new InvalidDataTypeException( |
|
| 391 | + '$form_args', |
|
| 392 | + $form_args, |
|
| 393 | + 'anything other than an object was expected.' |
|
| 394 | + ); |
|
| 395 | + } |
|
| 396 | + if (empty($form_args)) { |
|
| 397 | + throw new InvalidArgumentException( |
|
| 398 | + esc_html__('The redirect arguments can not be an empty array.', 'event_espresso') |
|
| 399 | + ); |
|
| 400 | + } |
|
| 401 | + $this->form_args = array_merge($this->form_args, $form_args); |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * @return string |
|
| 407 | + */ |
|
| 408 | + public function formConfig() |
|
| 409 | + { |
|
| 410 | + return $this->form_config; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * @param string $form_config |
|
| 416 | + * @throws DomainException |
|
| 417 | + */ |
|
| 418 | + public function setFormConfig($form_config) |
|
| 419 | + { |
|
| 420 | + if (! in_array( |
|
| 421 | + $form_config, |
|
| 422 | + array( |
|
| 423 | + FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 424 | + FormHandler::ADD_FORM_TAGS_ONLY, |
|
| 425 | + FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
| 426 | + FormHandler::DO_NOT_SETUP_FORM, |
|
| 427 | + ), |
|
| 428 | + true |
|
| 429 | + ) |
|
| 430 | + ) { |
|
| 431 | + throw new DomainException( |
|
| 432 | + sprintf( |
|
| 433 | + esc_html__( |
|
| 434 | + '"%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', |
|
| 435 | + 'event_espresso' |
|
| 436 | + ), |
|
| 437 | + $form_config |
|
| 438 | + ) |
|
| 439 | + ); |
|
| 440 | + } |
|
| 441 | + $this->form_config = $form_config; |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * called after the form is instantiated |
|
| 447 | + * and used for performing any logic that needs to occur early |
|
| 448 | + * before any of the other methods are called. |
|
| 449 | + * returns true if everything is ok to proceed, |
|
| 450 | + * and false if no further form logic should be implemented |
|
| 451 | + * |
|
| 452 | + * @return boolean |
|
| 453 | + */ |
|
| 454 | + public function initialize() |
|
| 455 | + { |
|
| 456 | + $this->form_has_errors = EE_Error::has_error(true); |
|
| 457 | + return true; |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * used for setting up css and js |
|
| 463 | + * |
|
| 464 | + * @return void |
|
| 465 | + * @throws LogicException |
|
| 466 | + * @throws EE_Error |
|
| 467 | + */ |
|
| 468 | + public function enqueueStylesAndScripts() |
|
| 469 | + { |
|
| 470 | + $this->form()->enqueue_js(); |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + |
|
| 474 | + /** |
|
| 475 | + * creates and returns the actual form |
|
| 476 | + * |
|
| 477 | + * @return EE_Form_Section_Proper |
|
| 478 | + */ |
|
| 479 | + abstract public function generate(); |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * creates and returns an EE_Submit_Input labeled "Submit" |
|
| 484 | + * |
|
| 485 | + * @param string $text |
|
| 486 | + * @return EE_Submit_Input |
|
| 487 | + */ |
|
| 488 | + public function generateSubmitButton($text = '') |
|
| 489 | + { |
|
| 490 | + $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
| 491 | + return new EE_Submit_Input( |
|
| 492 | + array( |
|
| 493 | + 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
| 494 | + 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
| 495 | + 'html_class' => 'ee-form-submit', |
|
| 496 | + 'html_label' => ' ', |
|
| 497 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
| 498 | + 'default' => $text, |
|
| 499 | + ) |
|
| 500 | + ); |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + |
|
| 504 | + /** |
|
| 505 | + * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
| 506 | + * |
|
| 507 | + * @param string $text |
|
| 508 | + * @return void |
|
| 509 | + * @throws EE_Error |
|
| 510 | + */ |
|
| 511 | + public function appendSubmitButton($text = '') |
|
| 512 | + { |
|
| 513 | + if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
| 514 | + return; |
|
| 515 | + } |
|
| 516 | + $this->form->add_subsections( |
|
| 517 | + array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
| 518 | + null, |
|
| 519 | + false |
|
| 520 | + ); |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + |
|
| 524 | + /** |
|
| 525 | + * creates and returns an EE_Submit_Input labeled "Cancel" |
|
| 526 | + * |
|
| 527 | + * @param string $text |
|
| 528 | + * @return EE_Submit_Input |
|
| 529 | + */ |
|
| 530 | + public function generateCancelButton($text = '') |
|
| 531 | + { |
|
| 532 | + $cancel_button = new EE_Submit_Input( |
|
| 533 | + array( |
|
| 534 | + 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
| 535 | + 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
| 536 | + 'html_class' => 'ee-cancel-form', |
|
| 537 | + 'html_label' => ' ', |
|
| 538 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
| 539 | + 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
|
| 540 | + ) |
|
| 541 | + ); |
|
| 542 | + $cancel_button->set_button_css_attributes(false); |
|
| 543 | + return $cancel_button; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + |
|
| 547 | + /** |
|
| 548 | + * appends a float clearing div onto end of form |
|
| 549 | + * |
|
| 550 | + * @return void |
|
| 551 | + * @throws EE_Error |
|
| 552 | + */ |
|
| 553 | + public function clearFormButtonFloats() |
|
| 554 | + { |
|
| 555 | + $this->form->add_subsections( |
|
| 556 | + array( |
|
| 557 | + 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
|
| 558 | + EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
| 559 | + ), |
|
| 560 | + ), |
|
| 561 | + null, |
|
| 562 | + false |
|
| 563 | + ); |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + |
|
| 567 | + /** |
|
| 568 | + * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
| 569 | + * returns a string of HTML that can be directly echoed in a template |
|
| 570 | + * |
|
| 571 | + * @return string |
|
| 572 | + * @throws \InvalidArgumentException |
|
| 573 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 574 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 575 | + * @throws LogicException |
|
| 576 | + * @throws EE_Error |
|
| 577 | + */ |
|
| 578 | + public function display() |
|
| 579 | + { |
|
| 580 | + $form_html = apply_filters( |
|
| 581 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
|
| 582 | + '' |
|
| 583 | + ); |
|
| 584 | + $form_config = $this->formConfig(); |
|
| 585 | + if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 586 | + || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
| 587 | + ) { |
|
| 588 | + $form_html .= $this->form()->form_open($this->formAction()); |
|
| 589 | + } |
|
| 590 | + $form_html .= $this->form(true)->get_html(); |
|
| 591 | + if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 592 | + || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
| 593 | + ) { |
|
| 594 | + $form_html .= $this->form()->form_close(); |
|
| 595 | + } |
|
| 596 | + $form_html .= apply_filters( |
|
| 597 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form', |
|
| 598 | + '' |
|
| 599 | + ); |
|
| 600 | + return $form_html; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * handles processing the form submission |
|
| 606 | + * returns true or false depending on whether the form was processed successfully or not |
|
| 607 | + * |
|
| 608 | + * @param array $submitted_form_data |
|
| 609 | + * @return array |
|
| 610 | + * @throws \InvalidArgumentException |
|
| 611 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 612 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 613 | + * @throws EE_Error |
|
| 614 | + * @throws LogicException |
|
| 615 | + * @throws InvalidFormSubmissionException |
|
| 616 | + */ |
|
| 617 | + public function process($submitted_form_data = array()) |
|
| 618 | + { |
|
| 619 | + if (! $this->form()->was_submitted($submitted_form_data)) { |
|
| 620 | + throw new InvalidFormSubmissionException($this->form_name); |
|
| 621 | + } |
|
| 622 | + $this->form(true)->receive_form_submission($submitted_form_data); |
|
| 623 | + if (! $this->form()->is_valid()) { |
|
| 624 | + throw new InvalidFormSubmissionException( |
|
| 625 | + $this->form_name, |
|
| 626 | + sprintf( |
|
| 627 | + esc_html__( |
|
| 628 | + 'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s', |
|
| 629 | + 'event_espresso' |
|
| 630 | + ), |
|
| 631 | + $this->form_name, |
|
| 632 | + '<br />', |
|
| 633 | + implode('<br />', $this->form()->get_validation_errors_accumulated()) |
|
| 634 | + ) |
|
| 635 | + ); |
|
| 636 | + } |
|
| 637 | + return apply_filters( |
|
| 638 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data', |
|
| 639 | + $this->form()->valid_data(), |
|
| 640 | + $this |
|
| 641 | + ); |
|
| 642 | + } |
|
| 643 | 643 | } |
@@ -13,25 +13,25 @@ |
||
| 13 | 13 | class InvalidFormHandlerException extends \UnexpectedValueException |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * InvalidFormHandlerException constructor. |
|
| 18 | - * |
|
| 19 | - * @param string $actual the FormHandler object that was received |
|
| 20 | - * @param string $message |
|
| 21 | - * @param int $code |
|
| 22 | - * @param \Exception $previous |
|
| 23 | - */ |
|
| 24 | - public function __construct($actual, $message = '', $code = 0, \Exception $previous = null) |
|
| 25 | - { |
|
| 26 | - if (empty($message)) { |
|
| 27 | - $message = sprintf( |
|
| 28 | - __( |
|
| 29 | - 'A valid Form Handler was expected but instead "%1$s" was received.', |
|
| 30 | - 'event_espresso' |
|
| 31 | - ), |
|
| 32 | - $actual |
|
| 33 | - ); |
|
| 34 | - } |
|
| 35 | - parent::__construct($message, $code, $previous); |
|
| 36 | - } |
|
| 16 | + /** |
|
| 17 | + * InvalidFormHandlerException constructor. |
|
| 18 | + * |
|
| 19 | + * @param string $actual the FormHandler object that was received |
|
| 20 | + * @param string $message |
|
| 21 | + * @param int $code |
|
| 22 | + * @param \Exception $previous |
|
| 23 | + */ |
|
| 24 | + public function __construct($actual, $message = '', $code = 0, \Exception $previous = null) |
|
| 25 | + { |
|
| 26 | + if (empty($message)) { |
|
| 27 | + $message = sprintf( |
|
| 28 | + __( |
|
| 29 | + 'A valid Form Handler was expected but instead "%1$s" was received.', |
|
| 30 | + 'event_espresso' |
|
| 31 | + ), |
|
| 32 | + $actual |
|
| 33 | + ); |
|
| 34 | + } |
|
| 35 | + parent::__construct($message, $code, $previous); |
|
| 36 | + } |
|
| 37 | 37 | } |
@@ -14,10 +14,10 @@ |
||
| 14 | 14 | abstract class FormHtmlFilter |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @param $html |
|
| 19 | - * @param EE_Form_Section_Validatable $form_section |
|
| 20 | - * @return string |
|
| 21 | - */ |
|
| 22 | - abstract public function filterHtml($html, EE_Form_Section_Validatable $form_section); |
|
| 17 | + /** |
|
| 18 | + * @param $html |
|
| 19 | + * @param EE_Form_Section_Validatable $form_section |
|
| 20 | + * @return string |
|
| 21 | + */ |
|
| 22 | + abstract public function filterHtml($html, EE_Form_Section_Validatable $form_section); |
|
| 23 | 23 | } |
@@ -12,49 +12,49 @@ |
||
| 12 | 12 | class EventListIframeEmbedButton extends IframeEmbedButton |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * EventListIframeEmbedButton constructor. |
|
| 17 | - */ |
|
| 18 | - public function __construct() |
|
| 19 | - { |
|
| 20 | - parent::__construct( |
|
| 21 | - esc_html__('Upcoming Event List', 'event_espresso'), |
|
| 22 | - 'event_list' |
|
| 23 | - ); |
|
| 24 | - } |
|
| 15 | + /** |
|
| 16 | + * EventListIframeEmbedButton constructor. |
|
| 17 | + */ |
|
| 18 | + public function __construct() |
|
| 19 | + { |
|
| 20 | + parent::__construct( |
|
| 21 | + esc_html__('Upcoming Event List', 'event_espresso'), |
|
| 22 | + 'event_list' |
|
| 23 | + ); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | - public function addEmbedButton() |
|
| 28 | - { |
|
| 29 | - add_filter( |
|
| 30 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 31 | - array($this, 'addEventListIframeEmbedButtonSection') |
|
| 32 | - ); |
|
| 33 | - add_action( |
|
| 34 | - 'admin_enqueue_scripts', |
|
| 35 | - array($this, 'embedButtonAssets'), |
|
| 36 | - 10 |
|
| 37 | - ); |
|
| 38 | - } |
|
| 27 | + public function addEmbedButton() |
|
| 28 | + { |
|
| 29 | + add_filter( |
|
| 30 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 31 | + array($this, 'addEventListIframeEmbedButtonSection') |
|
| 32 | + ); |
|
| 33 | + add_action( |
|
| 34 | + 'admin_enqueue_scripts', |
|
| 35 | + array($this, 'embedButtonAssets'), |
|
| 36 | + 10 |
|
| 37 | + ); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Adds an iframe embed code button to the Event editor. |
|
| 43 | - * return string |
|
| 44 | - * |
|
| 45 | - * @param array $after_list_table |
|
| 46 | - * @return array |
|
| 47 | - */ |
|
| 48 | - public function addEventListIframeEmbedButtonSection(array $after_list_table) |
|
| 49 | - { |
|
| 50 | - return \EEH_Array::insert_into_array( |
|
| 51 | - $after_list_table, |
|
| 52 | - array( |
|
| 53 | - 'iframe_embed_buttons' => $this->addIframeEmbedButtonsSection( |
|
| 54 | - array('event_list' => $this->embedButtonHtml()) |
|
| 55 | - ), |
|
| 56 | - ), |
|
| 57 | - 'legend' |
|
| 58 | - ); |
|
| 59 | - } |
|
| 41 | + /** |
|
| 42 | + * Adds an iframe embed code button to the Event editor. |
|
| 43 | + * return string |
|
| 44 | + * |
|
| 45 | + * @param array $after_list_table |
|
| 46 | + * @return array |
|
| 47 | + */ |
|
| 48 | + public function addEventListIframeEmbedButtonSection(array $after_list_table) |
|
| 49 | + { |
|
| 50 | + return \EEH_Array::insert_into_array( |
|
| 51 | + $after_list_table, |
|
| 52 | + array( |
|
| 53 | + 'iframe_embed_buttons' => $this->addIframeEmbedButtonsSection( |
|
| 54 | + array('event_list' => $this->embedButtonHtml()) |
|
| 55 | + ), |
|
| 56 | + ), |
|
| 57 | + 'legend' |
|
| 58 | + ); |
|
| 59 | + } |
|
| 60 | 60 | } |
@@ -14,54 +14,54 @@ |
||
| 14 | 14 | class RestException extends \EE_Error |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var array |
|
| 19 | - */ |
|
| 20 | - protected $wp_error_data = array(); |
|
| 17 | + /** |
|
| 18 | + * @var array |
|
| 19 | + */ |
|
| 20 | + protected $wp_error_data = array(); |
|
| 21 | 21 | |
| 22 | - protected $wp_error_code = ''; |
|
| 22 | + protected $wp_error_code = ''; |
|
| 23 | 23 | |
| 24 | 24 | |
| 25 | 25 | |
| 26 | - public function __construct($string_code, $message, $wp_error_data = array(), $previous = null) |
|
| 27 | - { |
|
| 28 | - if (is_array($wp_error_data) |
|
| 29 | - && isset($wp_error_data['status']) |
|
| 30 | - ) { |
|
| 31 | - $http_status_number = $wp_error_data['status']; |
|
| 32 | - } else { |
|
| 33 | - $http_status_number = 500; |
|
| 34 | - } |
|
| 35 | - parent::__construct( |
|
| 36 | - $message, |
|
| 37 | - $http_status_number, |
|
| 38 | - $previous |
|
| 39 | - ); |
|
| 40 | - $this->wp_error_data = $wp_error_data; |
|
| 41 | - $this->wp_error_code = $string_code; |
|
| 42 | - } |
|
| 26 | + public function __construct($string_code, $message, $wp_error_data = array(), $previous = null) |
|
| 27 | + { |
|
| 28 | + if (is_array($wp_error_data) |
|
| 29 | + && isset($wp_error_data['status']) |
|
| 30 | + ) { |
|
| 31 | + $http_status_number = $wp_error_data['status']; |
|
| 32 | + } else { |
|
| 33 | + $http_status_number = 500; |
|
| 34 | + } |
|
| 35 | + parent::__construct( |
|
| 36 | + $message, |
|
| 37 | + $http_status_number, |
|
| 38 | + $previous |
|
| 39 | + ); |
|
| 40 | + $this->wp_error_data = $wp_error_data; |
|
| 41 | + $this->wp_error_code = $string_code; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | 44 | |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Array of data that may have been set during the constructor, intended for WP_Error's data |
|
| 48 | - * |
|
| 49 | - * @return array |
|
| 50 | - */ |
|
| 51 | - public function getData() |
|
| 52 | - { |
|
| 53 | - return $this->wp_error_data; |
|
| 54 | - } |
|
| 46 | + /** |
|
| 47 | + * Array of data that may have been set during the constructor, intended for WP_Error's data |
|
| 48 | + * |
|
| 49 | + * @return array |
|
| 50 | + */ |
|
| 51 | + public function getData() |
|
| 52 | + { |
|
| 53 | + return $this->wp_error_data; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | 56 | |
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Gets the error string |
|
| 60 | - * |
|
| 61 | - * @return string |
|
| 62 | - */ |
|
| 63 | - public function getStringCode() |
|
| 64 | - { |
|
| 65 | - return $this->wp_error_code; |
|
| 66 | - } |
|
| 58 | + /** |
|
| 59 | + * Gets the error string |
|
| 60 | + * |
|
| 61 | + * @return string |
|
| 62 | + */ |
|
| 63 | + public function getStringCode() |
|
| 64 | + { |
|
| 65 | + return $this->wp_error_code; |
|
| 66 | + } |
|
| 67 | 67 | } |
@@ -10,38 +10,38 @@ |
||
| 10 | 10 | class ChangesIn40834 extends ChangesInBase |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Adds hooks so requests to 4.8.29 don't have the checkin endpoints |
|
| 15 | - */ |
|
| 16 | - public function setHooks() |
|
| 17 | - { |
|
| 18 | - // set a hook to remove the checkout/checkout endpoints if the request |
|
| 19 | - // is for lower than 4.8.33 |
|
| 20 | - add_filter( |
|
| 21 | - 'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers', |
|
| 22 | - array($this, 'removeResponseHeaders'), |
|
| 23 | - 10, |
|
| 24 | - 3 |
|
| 25 | - ); |
|
| 26 | - } |
|
| 13 | + /** |
|
| 14 | + * Adds hooks so requests to 4.8.29 don't have the checkin endpoints |
|
| 15 | + */ |
|
| 16 | + public function setHooks() |
|
| 17 | + { |
|
| 18 | + // set a hook to remove the checkout/checkout endpoints if the request |
|
| 19 | + // is for lower than 4.8.33 |
|
| 20 | + add_filter( |
|
| 21 | + 'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers', |
|
| 22 | + array($this, 'removeResponseHeaders'), |
|
| 23 | + 10, |
|
| 24 | + 3 |
|
| 25 | + ); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Removes the checkin and checkout endpoints from the index for requests |
|
| 31 | - * to api versions lowers than 4.8.33 |
|
| 32 | - * |
|
| 33 | - * @param array $response_headers |
|
| 34 | - * @param Base $controller |
|
| 35 | - * @param string $requested_version |
|
| 36 | - * @return array like $routes_on_this_version |
|
| 37 | - */ |
|
| 38 | - public function removeResponseHeaders($response_headers, $controller, $requested_version) |
|
| 39 | - { |
|
| 40 | - if ($controller instanceof Base |
|
| 41 | - && $this->appliesToVersion($requested_version) |
|
| 42 | - ) { |
|
| 43 | - return array(); |
|
| 44 | - } |
|
| 45 | - return $response_headers; |
|
| 46 | - } |
|
| 29 | + /** |
|
| 30 | + * Removes the checkin and checkout endpoints from the index for requests |
|
| 31 | + * to api versions lowers than 4.8.33 |
|
| 32 | + * |
|
| 33 | + * @param array $response_headers |
|
| 34 | + * @param Base $controller |
|
| 35 | + * @param string $requested_version |
|
| 36 | + * @return array like $routes_on_this_version |
|
| 37 | + */ |
|
| 38 | + public function removeResponseHeaders($response_headers, $controller, $requested_version) |
|
| 39 | + { |
|
| 40 | + if ($controller instanceof Base |
|
| 41 | + && $this->appliesToVersion($requested_version) |
|
| 42 | + ) { |
|
| 43 | + return array(); |
|
| 44 | + } |
|
| 45 | + return $response_headers; |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -7,57 +7,57 @@ |
||
| 7 | 7 | class ChangesIn40833 extends ChangesInBase |
| 8 | 8 | { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * Adds hooks so requests to 4.8.29 don't have the checkin endpoints |
|
| 12 | - */ |
|
| 13 | - public function setHooks() |
|
| 14 | - { |
|
| 15 | - // set a hook to remove the checkout/checkout endpoints if the request |
|
| 16 | - // is for lower than 4.8.33 |
|
| 17 | - add_filter( |
|
| 18 | - 'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes', |
|
| 19 | - array($this, 'removeCheckinRoutesEarlierThan4833'), |
|
| 20 | - 10, |
|
| 21 | - 2 |
|
| 22 | - ); |
|
| 23 | - add_filter( |
|
| 24 | - 'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_headers_from_ee_notices__return', |
|
| 25 | - array($this, 'dontAddHeadersFromEeNotices'), |
|
| 26 | - 10, |
|
| 27 | - 2 |
|
| 28 | - ); |
|
| 29 | - } |
|
| 10 | + /** |
|
| 11 | + * Adds hooks so requests to 4.8.29 don't have the checkin endpoints |
|
| 12 | + */ |
|
| 13 | + public function setHooks() |
|
| 14 | + { |
|
| 15 | + // set a hook to remove the checkout/checkout endpoints if the request |
|
| 16 | + // is for lower than 4.8.33 |
|
| 17 | + add_filter( |
|
| 18 | + 'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes', |
|
| 19 | + array($this, 'removeCheckinRoutesEarlierThan4833'), |
|
| 20 | + 10, |
|
| 21 | + 2 |
|
| 22 | + ); |
|
| 23 | + add_filter( |
|
| 24 | + 'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_headers_from_ee_notices__return', |
|
| 25 | + array($this, 'dontAddHeadersFromEeNotices'), |
|
| 26 | + 10, |
|
| 27 | + 2 |
|
| 28 | + ); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Removes the checkin and checkout endpoints from the index for requests |
|
| 34 | - * to api versions lowers than 4.8.33 |
|
| 35 | - * |
|
| 36 | - * @param array $routes_on_this_version |
|
| 37 | - * @param string $version |
|
| 38 | - * @return array like $routes_on_this_version |
|
| 39 | - */ |
|
| 40 | - public function removeCheckinRoutesEarlierThan4833($routes_on_this_version, $version) |
|
| 41 | - { |
|
| 42 | - if ($this->appliesToVersion($version)) { |
|
| 43 | - unset($routes_on_this_version['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)']); |
|
| 44 | - } |
|
| 45 | - return $routes_on_this_version; |
|
| 46 | - } |
|
| 32 | + /** |
|
| 33 | + * Removes the checkin and checkout endpoints from the index for requests |
|
| 34 | + * to api versions lowers than 4.8.33 |
|
| 35 | + * |
|
| 36 | + * @param array $routes_on_this_version |
|
| 37 | + * @param string $version |
|
| 38 | + * @return array like $routes_on_this_version |
|
| 39 | + */ |
|
| 40 | + public function removeCheckinRoutesEarlierThan4833($routes_on_this_version, $version) |
|
| 41 | + { |
|
| 42 | + if ($this->appliesToVersion($version)) { |
|
| 43 | + unset($routes_on_this_version['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)']); |
|
| 44 | + } |
|
| 45 | + return $routes_on_this_version; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * We just added headers for notices in this version |
|
| 51 | - * |
|
| 52 | - * @param array $headers_from_ee_notices |
|
| 53 | - * @param string $requested_version |
|
| 54 | - * @return array |
|
| 55 | - */ |
|
| 56 | - public function dontAddHeadersFromEeNotices($headers_from_ee_notices, $requested_version) |
|
| 57 | - { |
|
| 58 | - if ($this->appliesToVersion($requested_version)) { |
|
| 59 | - return array(); |
|
| 60 | - } |
|
| 61 | - return $headers_from_ee_notices; |
|
| 62 | - } |
|
| 49 | + /** |
|
| 50 | + * We just added headers for notices in this version |
|
| 51 | + * |
|
| 52 | + * @param array $headers_from_ee_notices |
|
| 53 | + * @param string $requested_version |
|
| 54 | + * @return array |
|
| 55 | + */ |
|
| 56 | + public function dontAddHeadersFromEeNotices($headers_from_ee_notices, $requested_version) |
|
| 57 | + { |
|
| 58 | + if ($this->appliesToVersion($requested_version)) { |
|
| 59 | + return array(); |
|
| 60 | + } |
|
| 61 | + return $headers_from_ee_notices; |
|
| 62 | + } |
|
| 63 | 63 | } |
@@ -26,124 +26,124 @@ |
||
| 26 | 26 | class Checkin extends Base |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @param WP_REST_Request $request |
|
| 31 | - * @param string $version |
|
| 32 | - * @return WP_Error|WP_REST_Response |
|
| 33 | - */ |
|
| 34 | - public static function handleRequestToggleCheckin(WP_REST_Request $request, $version) |
|
| 35 | - { |
|
| 36 | - $controller = new Checkin(); |
|
| 37 | - return $controller->createCheckinCheckoutObject($request, $version); |
|
| 38 | - } |
|
| 29 | + /** |
|
| 30 | + * @param WP_REST_Request $request |
|
| 31 | + * @param string $version |
|
| 32 | + * @return WP_Error|WP_REST_Response |
|
| 33 | + */ |
|
| 34 | + public static function handleRequestToggleCheckin(WP_REST_Request $request, $version) |
|
| 35 | + { |
|
| 36 | + $controller = new Checkin(); |
|
| 37 | + return $controller->createCheckinCheckoutObject($request, $version); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Toggles whether the user is checked in or not. |
|
| 43 | - * |
|
| 44 | - * @param WP_REST_Request $request |
|
| 45 | - * @param string $version |
|
| 46 | - * @return WP_Error|WP_REST_Response |
|
| 47 | - */ |
|
| 48 | - protected function createCheckinCheckoutObject(WP_REST_Request $request, $version) |
|
| 49 | - { |
|
| 50 | - $reg_id = $request->get_param('REG_ID'); |
|
| 51 | - $dtt_id = $request->get_param('DTT_ID'); |
|
| 52 | - $force = $request->get_param('force'); |
|
| 53 | - if ($force == 'true') { |
|
| 54 | - $force = true; |
|
| 55 | - } else { |
|
| 56 | - $force = false; |
|
| 57 | - } |
|
| 58 | - $reg = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
| 59 | - if (! $reg instanceof EE_Registration) { |
|
| 60 | - return $this->sendResponse( |
|
| 61 | - new WP_Error( |
|
| 62 | - 'rest_registration_toggle_checkin_invalid_id', |
|
| 63 | - sprintf( |
|
| 64 | - __( |
|
| 65 | - 'You cannot checkin registration with ID %1$s because it doesn\'t exist.', |
|
| 66 | - 'event_espresso' |
|
| 67 | - ), |
|
| 68 | - $reg_id |
|
| 69 | - ), |
|
| 70 | - array('status' => 422) |
|
| 71 | - ) |
|
| 72 | - ); |
|
| 73 | - } |
|
| 74 | - if (! EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) { |
|
| 75 | - return $this->sendResponse( |
|
| 76 | - new WP_Error( |
|
| 77 | - 'rest_user_cannot_toggle_checkin', |
|
| 78 | - sprintf( |
|
| 79 | - __('You are not allowed to checkin registration with ID %1$s.', 'event_espresso'), |
|
| 80 | - $reg_id |
|
| 81 | - ), |
|
| 82 | - array('status' => 403) |
|
| 83 | - ) |
|
| 84 | - ); |
|
| 85 | - } |
|
| 86 | - $success = $reg->toggle_checkin_status($dtt_id, ! $force); |
|
| 87 | - if ($success === false) { |
|
| 88 | - // check if we know they can't check in because they're not approved and we aren't forcing |
|
| 89 | - if (! $reg->is_approved() && ! $force) { |
|
| 90 | - // rely on EE_Error::add_error messages to have been added to give more data about why it failed |
|
| 91 | - return $this->sendResponse( |
|
| 92 | - new WP_Error( |
|
| 93 | - 'rest_toggle_checkin_failed', |
|
| 94 | - __( |
|
| 95 | - // @codingStandardsIgnoreStart |
|
| 96 | - 'Registration check-in failed because the registration is not approved. You may attempt to force checking in though.', |
|
| 97 | - // @codingStandardsIgnoreEnd |
|
| 98 | - 'event_espresso' |
|
| 99 | - ) |
|
| 100 | - ) |
|
| 101 | - ); |
|
| 102 | - } |
|
| 103 | - return $this->sendResponse( |
|
| 104 | - new WP_Error( |
|
| 105 | - 'rest_toggle_checkin_failed_not_forceable', |
|
| 106 | - __('Registration checkin failed. Please see additional error data.', 'event_espresso') |
|
| 107 | - ) |
|
| 108 | - ); |
|
| 109 | - } |
|
| 110 | - $checkin = EEM_Checkin::instance()->get_one( |
|
| 111 | - array( |
|
| 112 | - array( |
|
| 113 | - 'REG_ID' => $reg_id, |
|
| 114 | - 'DTT_ID' => $dtt_id, |
|
| 115 | - ), |
|
| 116 | - 'order_by' => array( |
|
| 117 | - 'CHK_timestamp' => 'DESC', |
|
| 118 | - ), |
|
| 119 | - ) |
|
| 120 | - ); |
|
| 121 | - if (! $checkin instanceof EE_Checkin) { |
|
| 122 | - return $this->sendResponse( |
|
| 123 | - new WP_Error( |
|
| 124 | - 'rest_toggle_checkin_error', |
|
| 125 | - sprintf( |
|
| 126 | - __( |
|
| 127 | - // @codingStandardsIgnoreStart |
|
| 128 | - 'Supposedly we created a new checkin object for registration %1$s at datetime %2$s, but we can\'t find it.', |
|
| 129 | - // @codingStandardsIgnoreEnd |
|
| 130 | - 'event_espresso' |
|
| 131 | - ), |
|
| 132 | - $reg_id, |
|
| 133 | - $dtt_id |
|
| 134 | - ) |
|
| 135 | - ) |
|
| 136 | - ); |
|
| 137 | - } |
|
| 138 | - $get_request = new WP_REST_Request( |
|
| 139 | - 'GET', |
|
| 140 | - '/' . EED_Core_Rest_Api::ee_api_namespace . 'v' . $version . '/checkins/' . $checkin->ID() |
|
| 141 | - ); |
|
| 142 | - $get_request->set_url_params( |
|
| 143 | - array( |
|
| 144 | - 'id' => $checkin->ID(), |
|
| 145 | - ) |
|
| 146 | - ); |
|
| 147 | - return Read::handleRequestGetOne($get_request, $version, 'Checkin'); |
|
| 148 | - } |
|
| 41 | + /** |
|
| 42 | + * Toggles whether the user is checked in or not. |
|
| 43 | + * |
|
| 44 | + * @param WP_REST_Request $request |
|
| 45 | + * @param string $version |
|
| 46 | + * @return WP_Error|WP_REST_Response |
|
| 47 | + */ |
|
| 48 | + protected function createCheckinCheckoutObject(WP_REST_Request $request, $version) |
|
| 49 | + { |
|
| 50 | + $reg_id = $request->get_param('REG_ID'); |
|
| 51 | + $dtt_id = $request->get_param('DTT_ID'); |
|
| 52 | + $force = $request->get_param('force'); |
|
| 53 | + if ($force == 'true') { |
|
| 54 | + $force = true; |
|
| 55 | + } else { |
|
| 56 | + $force = false; |
|
| 57 | + } |
|
| 58 | + $reg = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
| 59 | + if (! $reg instanceof EE_Registration) { |
|
| 60 | + return $this->sendResponse( |
|
| 61 | + new WP_Error( |
|
| 62 | + 'rest_registration_toggle_checkin_invalid_id', |
|
| 63 | + sprintf( |
|
| 64 | + __( |
|
| 65 | + 'You cannot checkin registration with ID %1$s because it doesn\'t exist.', |
|
| 66 | + 'event_espresso' |
|
| 67 | + ), |
|
| 68 | + $reg_id |
|
| 69 | + ), |
|
| 70 | + array('status' => 422) |
|
| 71 | + ) |
|
| 72 | + ); |
|
| 73 | + } |
|
| 74 | + if (! EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) { |
|
| 75 | + return $this->sendResponse( |
|
| 76 | + new WP_Error( |
|
| 77 | + 'rest_user_cannot_toggle_checkin', |
|
| 78 | + sprintf( |
|
| 79 | + __('You are not allowed to checkin registration with ID %1$s.', 'event_espresso'), |
|
| 80 | + $reg_id |
|
| 81 | + ), |
|
| 82 | + array('status' => 403) |
|
| 83 | + ) |
|
| 84 | + ); |
|
| 85 | + } |
|
| 86 | + $success = $reg->toggle_checkin_status($dtt_id, ! $force); |
|
| 87 | + if ($success === false) { |
|
| 88 | + // check if we know they can't check in because they're not approved and we aren't forcing |
|
| 89 | + if (! $reg->is_approved() && ! $force) { |
|
| 90 | + // rely on EE_Error::add_error messages to have been added to give more data about why it failed |
|
| 91 | + return $this->sendResponse( |
|
| 92 | + new WP_Error( |
|
| 93 | + 'rest_toggle_checkin_failed', |
|
| 94 | + __( |
|
| 95 | + // @codingStandardsIgnoreStart |
|
| 96 | + 'Registration check-in failed because the registration is not approved. You may attempt to force checking in though.', |
|
| 97 | + // @codingStandardsIgnoreEnd |
|
| 98 | + 'event_espresso' |
|
| 99 | + ) |
|
| 100 | + ) |
|
| 101 | + ); |
|
| 102 | + } |
|
| 103 | + return $this->sendResponse( |
|
| 104 | + new WP_Error( |
|
| 105 | + 'rest_toggle_checkin_failed_not_forceable', |
|
| 106 | + __('Registration checkin failed. Please see additional error data.', 'event_espresso') |
|
| 107 | + ) |
|
| 108 | + ); |
|
| 109 | + } |
|
| 110 | + $checkin = EEM_Checkin::instance()->get_one( |
|
| 111 | + array( |
|
| 112 | + array( |
|
| 113 | + 'REG_ID' => $reg_id, |
|
| 114 | + 'DTT_ID' => $dtt_id, |
|
| 115 | + ), |
|
| 116 | + 'order_by' => array( |
|
| 117 | + 'CHK_timestamp' => 'DESC', |
|
| 118 | + ), |
|
| 119 | + ) |
|
| 120 | + ); |
|
| 121 | + if (! $checkin instanceof EE_Checkin) { |
|
| 122 | + return $this->sendResponse( |
|
| 123 | + new WP_Error( |
|
| 124 | + 'rest_toggle_checkin_error', |
|
| 125 | + sprintf( |
|
| 126 | + __( |
|
| 127 | + // @codingStandardsIgnoreStart |
|
| 128 | + 'Supposedly we created a new checkin object for registration %1$s at datetime %2$s, but we can\'t find it.', |
|
| 129 | + // @codingStandardsIgnoreEnd |
|
| 130 | + 'event_espresso' |
|
| 131 | + ), |
|
| 132 | + $reg_id, |
|
| 133 | + $dtt_id |
|
| 134 | + ) |
|
| 135 | + ) |
|
| 136 | + ); |
|
| 137 | + } |
|
| 138 | + $get_request = new WP_REST_Request( |
|
| 139 | + 'GET', |
|
| 140 | + '/' . EED_Core_Rest_Api::ee_api_namespace . 'v' . $version . '/checkins/' . $checkin->ID() |
|
| 141 | + ); |
|
| 142 | + $get_request->set_url_params( |
|
| 143 | + array( |
|
| 144 | + 'id' => $checkin->ID(), |
|
| 145 | + ) |
|
| 146 | + ); |
|
| 147 | + return Read::handleRequestGetOne($get_request, $version, 'Checkin'); |
|
| 148 | + } |
|
| 149 | 149 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | $force = false; |
| 57 | 57 | } |
| 58 | 58 | $reg = EEM_Registration::instance()->get_one_by_ID($reg_id); |
| 59 | - if (! $reg instanceof EE_Registration) { |
|
| 59 | + if ( ! $reg instanceof EE_Registration) { |
|
| 60 | 60 | return $this->sendResponse( |
| 61 | 61 | new WP_Error( |
| 62 | 62 | 'rest_registration_toggle_checkin_invalid_id', |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | ) |
| 72 | 72 | ); |
| 73 | 73 | } |
| 74 | - if (! EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) { |
|
| 74 | + if ( ! EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) { |
|
| 75 | 75 | return $this->sendResponse( |
| 76 | 76 | new WP_Error( |
| 77 | 77 | 'rest_user_cannot_toggle_checkin', |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | $success = $reg->toggle_checkin_status($dtt_id, ! $force); |
| 87 | 87 | if ($success === false) { |
| 88 | 88 | // check if we know they can't check in because they're not approved and we aren't forcing |
| 89 | - if (! $reg->is_approved() && ! $force) { |
|
| 89 | + if ( ! $reg->is_approved() && ! $force) { |
|
| 90 | 90 | // rely on EE_Error::add_error messages to have been added to give more data about why it failed |
| 91 | 91 | return $this->sendResponse( |
| 92 | 92 | new WP_Error( |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | ), |
| 119 | 119 | ) |
| 120 | 120 | ); |
| 121 | - if (! $checkin instanceof EE_Checkin) { |
|
| 121 | + if ( ! $checkin instanceof EE_Checkin) { |
|
| 122 | 122 | return $this->sendResponse( |
| 123 | 123 | new WP_Error( |
| 124 | 124 | 'rest_toggle_checkin_error', |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | } |
| 138 | 138 | $get_request = new WP_REST_Request( |
| 139 | 139 | 'GET', |
| 140 | - '/' . EED_Core_Rest_Api::ee_api_namespace . 'v' . $version . '/checkins/' . $checkin->ID() |
|
| 140 | + '/'.EED_Core_Rest_Api::ee_api_namespace.'v'.$version.'/checkins/'.$checkin->ID() |
|
| 141 | 141 | ); |
| 142 | 142 | $get_request->set_url_params( |
| 143 | 143 | array( |
@@ -13,5 +13,5 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | abstract class JobHandler implements JobHandlerInterface |
| 15 | 15 | { |
| 16 | - // so far no common methods or properties |
|
| 16 | + // so far no common methods or properties |
|
| 17 | 17 | } |