By kim.pepper on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
9.3.x
Introduced in version:
9.3.0
Issue links:
Description:
_file_save_upload_single() has been deprecated and moved to a new service.
Before:
$file = _file_save_upload_single($file_info, $form_field_name)
After:
/** @var \Drupal\file\Upload\FileUploadHandler $file_upload_handler */
$file_upload_handler = \Drupal::service('file.upload_handler');
$result = $file_upload_handler->handleFileUpload($uploadedFile);
$file = $result->getFile();
NB:_file_save_upload_single() was considered 'internal' and should not have been called directly. The are not many use-cases for the new service unless you are handling files at a very low level. Ideally custom and contrib code should use the managed file API when uploading a file via a form or the jsonapi / rest api class for http requests.
$file->source is no longer set. It was erroneously assumed $file was a file entity and setting $file->source had no effect.
Impacts:
Module developers