PluginProbe
The Innovative Form Builder – IvyForms / 1.5
The Innovative Form Builder – IvyForms v1.5
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
← All changes | backend/src/Controllers/Form/UpdateFormController.php +16 -12 0.5 → 1.5 View file →
@@ -1,18 +1,13 @@
1 1 <?php
2 2
3 3 /**
4 - * @copyright © TMS-Plugins. All rights reserved.
4 + * @copyright © Melograno Venture Studio. All rights reserved.
5 5 * @licence See COPYING.md for license details.
6 6 */
7 7
8 8 namespace IvyForms\Controllers\Form;
9 9
10 -// phpcs:disable PSR1.Files.SideEffects
11 -if (!defined('ABSPATH')) {
12 - exit; // Exit if accessed directly
13 -}
14 -
15 10 use IvyForms\Common\Exceptions\ForbiddenException;
16 11 use IvyForms\Common\Exceptions\InvalidArgumentException;
17 12 use IvyForms\Common\Exceptions\QueryExecutionException;
18 13 use IvyForms\Common\Exceptions\ValidationException;
@@ -18,9 +13,8 @@
18 13 use IvyForms\Common\Exceptions\ValidationException;
19 14 use IvyForms\Common\Sanitizer\Sanitizer;
20 15 use IvyForms\Controllers\Controller;
21 16 use IvyForms\Services\Field\FieldService;
22 -use IvyForms\Services\Field\FieldType;
23 17 use IvyForms\Services\Form\FormService;
24 18 use IvyForms\Services\Translations\BackendStrings;
25 19 use WP_REST_Request;
26 20 use WP_REST_Response;
@@ -55,23 +49,25 @@
55 49 throw new InvalidArgumentException(
56 50 BackendStrings::getExceptionStrings()['invalid_request_data']
57 51 );
58 52 }
59 - $params = Sanitizer::sanitizeFormData($data->get_params());
60 53
54 + $formId = (int) $data->get_param('id');
55 +
56 + $params = Sanitizer::sanitizeFormData(
57 + $this->formService->withPreservedFormType($data->get_params(), $formId)
58 + );
59 +
61 60 $this->fieldService->validateFieldsType($params['fields']);
62 61
63 - // Update the form
64 62 [$formId, $form] = $this->formService->updateFormOrFail($params);
65 63 if (!$formId) {
66 64 throw new QueryExecutionException(BackendStrings::getAllFormsStrings()['failed_to_update_form'] . '.');
67 65 }
68 66
69 - // Get all existing field IDs for the form
70 67 $existingFieldIds = $this->fieldService->collectExistingFieldIds($formId);
71 68 $submittedFieldIds = [];
72 69
73 - // Update/add all submitted fields (including options and parent/child logic)
74 70 if (!empty($params['fields'])) {
75 71 $submittedFieldIds = $this->fieldService->updateFieldsWithOptions(
76 72 $params['fields'],
77 73 $formId
@@ -77,9 +73,8 @@
77 73 $formId
78 74 );
79 75 }
80 76
81 - // Delete any fields (and their options) that are no longer present
82 77 if (!empty($existingFieldIds)) {
83 78 $idsToDelete = array_diff($existingFieldIds, $submittedFieldIds);
84 79 if (!empty($idsToDelete)) {
85 80 $this->fieldService->deleteFields($idsToDelete);
@@ -84,8 +79,17 @@
84 79 if (!empty($idsToDelete)) {
85 80 $this->fieldService->deleteFields($idsToDelete);
86 81 }
87 82 }
83 +
84 + /**
85 + * After a form row (and fields) are persisted.
86 + *
87 + * @param \IvyForms\Entity\Form\Form $form
88 + * @param int $formId
89 + * @param string $context create|update
90 + */
91 + do_action('ivyforms/form/after_persist', $form, $formId, 'update');
88 92
89 93 return new WP_REST_Response([
90 94 'message' => BackendStrings::getCommonStrings()['ok'],
91 95 'data' => $form->toArray()