From 3518d8ae0349929b4f1e843e3629a2120c84405a Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Fri, 10 Jan 2025 10:48:19 +1300 Subject: [PATCH] API Deprecate passing bool to Form::loadDataFrom() (#11542) --- src/Forms/Form.php | 15 ++++++++++++--- src/Forms/FormRequestHandler.php | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Forms/Form.php b/src/Forms/Form.php index ce78802151e..a1a8af6e3b5 100644 --- a/src/Forms/Form.php +++ b/src/Forms/Form.php @@ -1337,9 +1337,6 @@ public function validate(): ValidationResult * do not want them parsed as submitted data. MERGE_AS_SUBMITTED_VALUE does the opposite and forces the data to be * parsed as it would be submitted from a form. * - * For backwards compatibility reasons, this parameter can also be set to === true, which is the same as passing - * MERGE_CLEAR_MISSING - * * @param array $fieldList An optional list of fields to process. This can be useful when you have a * form that has some fields that save to one object, and some that save to another. * @return $this @@ -1353,8 +1350,20 @@ public function loadDataFrom($data, $mergeStrategy = 0, $fieldList = null) // Handle the backwards compatible case of passing "true" as the second argument if ($mergeStrategy === true) { + Deprecation::notice( + '5.4.0', + 'Passing `true` to the $mergeStrategy argument in ' . Form::class . '::loadDataFrom() is deprecated.' + . ' Pass ' . Form::class . '::MERGE_CLEAR_MISSING instead.', + Deprecation::SCOPE_GLOBAL + ); $mergeStrategy = Form::MERGE_CLEAR_MISSING; } elseif ($mergeStrategy === false) { + Deprecation::notice( + '5.4.0', + 'Passing `false` to the $mergeStrategy argument in ' . Form::class . '::loadDataFrom() is deprecated.' + . ' Pass 0 instead.', + Deprecation::SCOPE_GLOBAL + ); $mergeStrategy = 0; } diff --git a/src/Forms/FormRequestHandler.php b/src/Forms/FormRequestHandler.php index 69deb991bf2..f8928513bb6 100644 --- a/src/Forms/FormRequestHandler.php +++ b/src/Forms/FormRequestHandler.php @@ -134,7 +134,7 @@ public function httpSubmission($request) $allowedFields = array_keys($this->form->Fields()->saveableFields() ?? []); // Populate the form - $this->form->loadDataFrom($vars, true, $allowedFields); + $this->form->loadDataFrom($vars, Form::MERGE_CLEAR_MISSING, $allowedFields); // Protection against CSRF attacks $token = $this->form->getSecurityToken();