File form state value is invalid when #multiple is FALSE

Created on 6 April 2023, about 1 year ago
Updated 19 April 2023, about 1 year ago

Problem/Motivation

πŸ› Required flag on file forms breaks on validation Fixed introduced a change to how the default value is derived.

However this also introduced a bug with simple UploadedFile objects being casted into an array, rather than being wrapped.

https://stackoverflow.com/a/4345609

This breaks existing calls such as:

// Retrieve either the single UploadedFile object or an array of it.
$files = $form_state->getValue('file');

Steps to reproduce

Produce a test which confirms that the value returned by the form state is a valid UploadedFile object.

Proposed resolution

Do a check to see if the return value is not an array and then wrapping accordingly rather than casting.

e.g.

---    return (array) $uploaded_file;
+++    return is_array($uploaded_file) ? $uploaded_file : [$uploaded_file];

Remaining tasks

Provide issue fork/patch.

User interface changes

N/A

API changes

N/A

Release notes snippet

πŸ› Bug report
Status

Needs work

Version

9.5

Component
File systemΒ  β†’

Last updated about 5 hours ago

Created by

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024