- Issue created by @codebymikey
- @codebymikey opened merge request.
- Status changed to Needs review
about 1 year ago 11:43am 6 April 2023 The last submitted patch, 4: 3352632-file-form-state-value-4.diff, failed testing. View results β
- Status changed to Needs work
about 1 year ago 8:05pm 6 April 2023 - π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
Seems reasonable, just need to work through the failures
- π¦πΊAustralia Mingsong π¦πΊ
Test patch #4 by following steps:
1. Login as a user who has permission to access Interface translation import page('/admin/config/regional/translate/import').
2. Upload a translation file (.po) via that form.
3. After submitting that form. An error said
Exception: Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed in serialize() (line 157 of core/lib/Drupal/Core/Batch/BatchStorage.php).
.
Test environment:
- Drupal core version: 9.5.7
- PHP version: 8.1.14
- π¦πΊAustralia Mingsong π¦πΊ
If we change line 97 at /core/lib/Drupal/Core/Render/Element/File.php
from
return is_array($uploaded_file) ? $uploaded_file : [$uploaded_file];
to
return is_array($uploaded_file) ? $uploaded_file : [(array) $uploaded_file];
All tests on my local is passed.
Here is the new patch.
- last update
about 1 year ago 30,322 pass - Status changed to Needs review
about 1 year ago 12:26am 18 April 2023 - Status changed to Needs work
about 1 year ago 1:17am 18 April 2023 - π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
+++ b/core/lib/Drupal/Core/Render/Element/File.php @@ -91,9 +91,9 @@ public static function valueCallback(&$element, $input, FormStateInterface $form + return is_array($uploaded_file) ? $uploaded_file : [(array) $uploaded_file];
this is an array of arrays, is that correct?
Can we add to the existing test coverage for this case?
See \Drupal\Tests\file\Kernel\ManagedFileTest
- last update
about 1 year ago 30,323 pass - Status changed to Needs review
about 1 year ago 4:21am 18 April 2023 - last update
about 1 year ago 30,323 pass - π¦πΊAustralia Mingsong π¦πΊ
There is a typo in patch #11.
New patch.
- last update
about 1 year ago 30,323 pass Appreciate the tests @Mingsong and finding where the proposed patch breaks things during serializations, the issue is that calls like this:
// Should ideally return an array of UploadedFile instances. $files = $form_state->getValue('file');
Should ideally still return an array of
\Symfony\Component\HttpFoundation\File\UploadedFile
instances, having it being casted to an array makes it harder to retrieve the original value from the form state.Unless we document that uploaded files should never be read from the
$form_state
but instead directly from the request (as core seems to handle it in most of its code).Or potentially introduce a new serializable class to wrap
\Symfony\Component\HttpFoundation\File\UploadedFile
and use that inside the form state (so that it can work in batch contexts).- Status changed to Needs work
about 1 year ago 12:03am 19 April 2023 - π¦πΊAustralia Mingsong π¦πΊ
Yes, I realized what @Mikey pointed too.
The problem is bigger than I thought. More works need to do.