Fix handling of unknown file extensions in FileMediaFormatterBase

Created on 7 August 2024, about 2 months ago
Updated 20 September 2024, 7 days ago

Problem/Motivation

If the list of allowed file extensions for a file field includes an unknown file extension, such as "foobaz", an error will be logged when viewing the rendered file field: Deprecated function: explode(): Passing null to parameter #2 ($string) of type string is deprecated in Drupal\file\Plugin\Field\FieldFormatter\FileMediaFormatterBase::mimeTypeApplies() (line 171 of core/modules/file/src/Plugin/Field/FieldFormatter/FileMediaFormatterBase.php)

Steps to reproduce

I suspect the list of allowed file extensions is processed in order, so the unknown file extension needs to precede the file extension used by the rendered file field. For example:

  1. Set the allowed file extensions for a file field to "foobaz, mp3"
  2. In display settings for the entity, configure the field to use the "Audio" (file_audio) field formatter.
  3. Create an entity with an attached mp3 file
  4. The error will be logged when rendering the entity.

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

๐Ÿ› Bug report
Status

RTBC

Version

11.0 ๐Ÿ”ฅ

Component
File systemย  โ†’

Last updated about 10 hours ago

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States mfb San Francisco

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

Comments & Activities

Production build 0.71.5 2024