Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Deprecate passing bool to Form::loadDataFrom() #11542

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading