Skip to content

Commit

Permalink
API Deprecate passing bool to Form::loadDataFrom() (#11542)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Jan 9, 2025
1 parent 99caf2d commit 3518d8a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/Forms/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Forms/FormRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 3518d8a

Please sign in to comment.