Skip to content

refactor!: pass the file to MediaHandler as a Symfony File - #6783

Merged
gharlan merged 1 commit into
6.xfrom
media-handler-file
Oct 21, 2026
Merged

gharlan merged 1 commit into
6.xfrom
media-handler-file

Conversation

@gharlan

@gharlan gharlan commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

MediaHandler::add()/edit() took the file in the $_FILES shape (name, tmp_name/path, error). Now $data['file'] is a Symfony File (symfony/http-foundation is already a dependency):

// upload, e.g. in an addon's frontend form
MediaHandler::add([
    'file' => Core::getRequest()->files->get('file'), // or new UploadedFile($f['tmp_name'], $f['name'], error: $f['error'])
    'category_id' => null,
    'title' => 'Foo',
]);

// file already on disk (sync, import)
MediaHandler::add(['file' => new File($path), 'category_id' => 5], subindexing: false);
  • The upload errors are still handled by the handler, so callers taking an upload don't have to do it themselves. UploadedFile::isValid() additionally ensures the file really was uploaded via http (is_uploaded_file()); previously "is an upload" only depended on tmp_name being set.
  • MediaAdding::$isUpload is derived from instanceof UploadedFile.

Breaking changes

Signatures aligned with the other handlers ($meta right after $data, options after it, the language as required second parameter of edit()):

MediaHandler::add($data, $doSubindexing, $types, $meta)  -> add($data, $meta, $subindexing, $types)
MediaHandler::edit($filename, $data, $languageId, $meta) -> edit($filename, $languageId, $data, $meta)
  • $data['file'] is a Symfony\Component\HttpFoundation\File\File instead of an array
  • edit(): missing keys keep their value, category_id and title are no longer required; file replaces the file
  • add(): title is optional

Tested in the backend: upload, edit with and without replacing the file, sync.

@gharlan gharlan added this to the REDAXO 6.0 milestone Oct 21, 2026
Base automatically changed from handler-params to 6.x October 21, 2026 19:30
`MediaHandler::add()`/`edit()` took the file in the `$_FILES` shape (`name`, `tmp_name`/`path`, `error`). Now
`$data['file']` is a Symfony `File`, an `UploadedFile` for uploads, e.g. `Core::getRequest()->files->get('file')`.
The upload errors are still handled by the handler, and `isValid()` additionally ensures that an `UploadedFile` really
was uploaded via http. The `isUpload` flag of `MediaAdding` is derived from the class.

The signatures follow the other handlers: `$meta` comes right after `$data`, the options after it, and `edit()` takes
the language as required second parameter:

    MediaHandler::add($data, $doSubindexing, $types, $meta)  -> add($data, $meta, $subindexing, $types)
    MediaHandler::edit($filename, $data, $languageId, $meta) -> edit($filename, $languageId, $data, $meta)

In `edit()` missing keys keep their value, `category_id` and `title` are no longer required. In `add()` `title` is
optional.
@gharlan
gharlan force-pushed the media-handler-file branch from 2b2bcc5 to c4e5fd3 Compare October 21, 2026 19:33
@gharlan
gharlan merged commit 8948f58 into 6.x Oct 21, 2026
16 checks passed
@gharlan
gharlan deleted the media-handler-file branch October 21, 2026 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants