Deprecate file_managed_file_save_upload(), file_save_upload() and _file_save_upload_from_form() and replace with a service

Created on 19 July 2023, 11 months ago
Updated 20 June 2024, 8 days ago

Problem/Motivation

Part of πŸ“Œ [META] Modernise file upload logic Active . Replace file_managed_file_save_upload(), file_save_upload() and _file_save_upload_from_form with new services to separate the Form API and user-facing messages from API-level services.

Steps to reproduce

Current sequence:

Proposed resolution

Notes on error handling

  • FileElementHelper::saveFileUploads() combines error messages as a list then sets them via FormStateInterface::setError()
  • FormFileUploader::saveFormUploadedFiles() has a bool $addErrorMessages param so error messages can be added via Messenger::addError() when this is called as an API method directly

Reasoning:

Currently file_managed_file_save_upload() and _file_save_upload_from_form() have behavior to combine upload errors and display them in a list, only if there is more than one. It does this by manipulating error messages (removing them, storing them, then re-adding them as a form error).

Default behaviour of file_save_upload() is just to add Messenger error messages.

Proposed sequence:

Remaining tasks

  • Add tests for new services
  • Add legacy tests for deprecated functions

User interface changes

API changes

  • file_managed_file_save_upload(), _file_save_upload_from_form and file_save_upload()are deprecated
  • New \Drupal\file\Upload\FileElementHelperand \Drupal\file\Upload\FormFileUploadHandler services are added
  • A new FileUploaded event is dispatched on success of individual file uploads

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
File moduleΒ  β†’

Last updated 1 day ago

Created by

πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia

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

Merge Requests

Comments & Activities

Production build 0.69.0 2024