Make file field save file language

Created on 5 June 2014, about 11 years ago
Updated 14 July 2025, 2 days ago

Problem/Motivation

When working on #2215507: Downloads broken for translated private files β†’ I noticed that function file_save_upload() does not set File's entity language. This makes File entity to always be saved with hardcoded default language regardless of actual parent language.

For example when saving file field of English node, the File entity language is always 'und'. The same for any other language on mono or multilingual sites.

I think this is wrong especially for translated entities that might actually use different files for their translations. So it would make sense to set File entity language if saving file uploaded via field form.

Also, saving language with a file might help when managing files in core (see #2215507-5: Downloads broken for translated private files β†’ ) or with contributed modules. The schema is there it's just that it doesn't seem to be used at all.

Proposed resolution

Unfortunately the file_save_upload() does not provide a way of setting file's language. So I see two options:

  1. The function file_save_upload() could accept another parameter specifying language or langcode.
  2. The function file_managed_file_save_upload() that in this case invokes file_save_upload(), could set language of the File entity and update it after file_save_upload() returns.

Remaining tasks

Discuss possible solutions and consequences. Create patch.

User interface changes

None.

API changes

Maybe a small change in file_save_upload() definition (one more parameter)?

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component

file system

Created by

πŸ‡΅πŸ‡±Poland SiliconMind

Live updates comments and jobs are added and updated live.
  • D8MI

    (Drupal 8 Multilingual Initiative) is the tag used by the multilingual initiative to mark core issues (and some contributed module issues). For versions other than Drupal 8, use the i18n (Internationalization) tag on issues which involve or affect multilingual / multinational support. That is preferred over Translation.

Sign in to follow issues

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