TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in count() (line 195 of /var/www/html/web/core/modules/media_library/src/Form/FileUploadForm.php)
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | 3246558-5.patch | 2.32 KB | bingol@ciandt.com |
| media-libary-php8.patch | 933 bytes | michiellucas |
Issue fork drupal-3246558
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3246558-php8-medialibrary-argument
compare
- 3246558-php8-error
changes, plain diff MR !8550
Comments
Comment #2
longwaveHow did you trigger this error?
Comment #3
michiellucas commentedusing the add media button -> popup (ajax) not working
Comment #4
larowlanCan you provide a stack trace or steps to reproduce, starting from installing core
Thanks
Also, some specs regarding your environment etc
Comment #6
pfrenssenI had this error also but it was due to a configuration error on my part. I have a media type that has an additional "Cover image" field. This field had a misconfiguration in the form display mode: it was set to display the preview image using the image style "thumbnail" which I suspect is the default, but this image style does not exist in my project.
When I added a new media entity using the media library "Add media" dialog and uploaded a cover image, the AJAX call would fail inside
template_preprocess_image_style()in this part of the code:This would cause the AJAX request to return a 500 error, so the file widget was not replaced and the file ID was not set in the form. When then the media library file upload form was submitted using either the "Save and select" or "Save and insert" buttons, then the error mentioned in the issue summary was thrown since
$values['fids']would not be populated.In my case the solution was to configure the form display of my media correctly. This made the error go away.
Still, it could be good to fix this, since the code path obviously has a deficiency:
So I am marking this as RTBC. Having this fixed is already valuable since it will not lead developers on the wrong path to solving the actual problem they are having (like mine I described above).
Since this is exceedingly minor and will not occur during normal use I think this is fine without having a dedicated test. If it is really needed to test this we can perhaps write a simple unit test that passes in a mocked form state with an empty 'upload' value, rather than simulating a failed AJAX request.
Comment #7
catchThis seems like it might be a core bug in itself - do we need to remove the hardcoding of 'thumbnail' or add some kind of fallback logic for when it's not there?
Comment #8
pfrenssenCreated followup to address the hardcoding of the
thumbnailimage style: #3263700: ImageWidget defaults to the "thumbnail" preview image style but this might not exist. It looks like we can best default to an empty string if the image style doesn't exist. This will set the preview image style to "No preview".Comment #9
catchI think we should do #3263700: ImageWidget defaults to the "thumbnail" preview image style but this might not exist first - this might end up repairing old configuration that would fix the bug in #6.
Comment #12
norman.lolRun into the same on D 9.4.9. Thumbnail exists. The patch fixes it for me. Full backtrace found in dblog:
Comment #13
anybodySame issue here now with PHP 8.1
Comment #14
anybodyThis message already pops up for me when opening the modal with the file upload widget on top and the media selection table below. At that point no file has been uploaded.
So it looks to me, as if the patch was needed or the code has to be adjusted?
It might be related to the other issue in some cases, but doesn't have to, I guess.
See screenshot below:

Comment #18
bingol@ciandt.com commentedComment #19
bingol@ciandt.com commentedComment #20
bingol@ciandt.com commentedComment #21
bingol@ciandt.com commented