File extensions allow only hardcoded extensions for images

Created on 18 April 2022, about 3 years ago
Updated 30 June 2025, 5 days ago

Problem/Motivation

I noticed that you can't change the allowed file extensions for image file entities. I tried changing the extensions List on all possible places you can define the allowed extensions. I checked here:

  1. I set it here /admin/config/media/file-settings
  2. I checked in the widget settings where the wanted (.webp) extension is set
  3. And I checked it in the field's settings

Everywhere I could think of where allowed file extensions can be set, are set. When I then upload a .webp image, it told me that the only allowed extensions are "png, gif, jpg, jpeg". I tried it with a field that doesn't use entity browser, it worked and took the allowed extensions from the field settings.

Steps to reproduce

These are the steps to reproduce the bug.

  1. Create an entity browser, the general settings can be left as it is.
  2. In the widget settings define a widget to upload files and one to view files. (An example is attached as a screenshot).
  3. Create a new field with the type "Image" on any entity type.
  4. In the field's settings define some file extensions you want. The only important thing is that there needs to be a file extension other than the defaults I wrote above. For example (png, gif, jpg, jpeg, webp)
  5. Go to «Manage form display» and set the previously defined entity browser as the fields widget.
  6. Now create a new node of the entity type that image field is and try to upload a .webp image file in the entity browser. There is an example in the attachment.

Proposed resolution

As I read the code to figure out where this file extension check is done I came to this file entity_browser/src/Plugin/Field/FieldWidget/FileBrowserWidget.php:506. There is a check which removes file extensions which aren't the default ones. I changed this line with this:

$extensions = array_unique(array_merge(explode(' ', $extensions), $supported_extensions));

If the array_insersect() is necessary, I can do a workaround with not using the image filed type and use the file entity type.

Let me know what you think about this.

Remaining tasks

-

User interface changes

There is no UI changes necessary to fix this.

API changes

Also there is no API changes necessary.

Data model changes

Also no data model changes are necessary.

🐛 Bug report
Status

Needs review

Version

2.0

Component

Field widget

Created by

🇨🇭Switzerland mandir

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024