Problem/Motivation

The media library adds it's upload forms by media_library_media_source_info_alter to the media sources.
This makes it impossible for contrib to overwrite these definitions. I ran into this while working on #3051658: Make dropzonejs widget available to the new Media Library in core, where I want to use a Dropzone upload form for images and files.

Proposed resolution

Specify the upload forms directly in the media sources, instead of a media_library_media_source_info_alter.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chr.fritsch created an issue. See original summary.

chr.fritsch’s picture

Status: Active » Needs review
FileSize
4.63 KB

Here is a patch.

Status: Needs review » Needs work

The last submitted patch, 2: 3171743.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

chr.fritsch’s picture

Status: Needs work » Needs review
FileSize
4.63 KB

Removing the prepending slash

Berdir’s picture

+++ b/core/modules/media/src/Plugin/media/Source/File.php
@@ -17,7 +17,10 @@
  *   allowed_field_types = {"file"},
- *   default_thumbnail_filename = "generic.png"
+ *   default_thumbnail_filename = "generic.png",
+ *   forms = {
+ *     "media_library_add" = "Drupal\media_library\Form\FileUploadForm",
+ *   }
  * )
  */
 class File extends MediaSourceBase {

I'm a bit confused. we can't have a reference to media_library in media module?

It might no be pretty, but you can be later than the media_library hook with a hook_module_implements_alter() or a module weight?

chr.fritsch’s picture

I'm a bit confused. we can't have a reference to media_library in media module?

It's not nice, but it doesn't harm IMHO.

It might no be pretty, but you can be later than the media_library hook with a hook_module_implements_alter() or a module weight?

I already thought about that, but that's really bad DX and I don't like that.

Berdir’s picture

Well, I don't think this will be accepted :)

Alternative: check in media library if the keys are already set and don't overwrite them then.

chr.fritsch’s picture

Yes, that's possible.

phenaproxima’s picture

Issue tags: +Needs tests

I am +1 for this refactoring, and I prefer the approach in #8. There is a reason why we did this with an alter hook in core -- it's so that Media wouldn't need to have any knowledge of Media Library's internals hard-coded into its plugin definitions.

Can we get a simple test of this?

chr.fritsch’s picture

In testMediaTypeAddForm we already test that the forms are set. I think that's ok.

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

Fair :) Looks legit to me, then!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I think we should have a kernel test that we can override them otherwise it'd be easy for this to regress.

chr.fritsch’s picture

Status: Needs work » Needs review
FileSize
5.19 KB

Added a test to ensure a different add form is used.

Status: Needs review » Needs work

The last submitted patch, 13: 3171743-13.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

chr.fritsch’s picture

Status: Needs work » Needs review

Random fail

paulocs’s picture

That's nice. Once I was trying to change the form using the media_library_media_source_info_alter() but I couldn't do it and I didn't even thought about patch #8.

I attached a new patch to fix code standard. But it looks good.

Cheers, Paulo.

volkerk’s picture

Status: Needs review » Reviewed & tested by the community

The test does work. Looks good to me.

alexpott’s picture

Title: Not possible to overwrite the upload forms for media library » [backport] Not possible to overwrite the upload forms for media library
Version: 9.1.x-dev » 9.0.x-dev
Issue tags: -Needs tests

Committed afba4ff and pushed to 9.1.x. Thanks!

This seems like a good thing for contrib. Also the risks seem minimal so triggering tests for 8.9.x and 9.0.x

  • alexpott committed afba4ff on 9.1.x
    Issue #3171743 by chr.fritsch, paulocs, Berdir, phenaproxima: Not...
alexpott’s picture

Version: 9.0.x-dev » 8.9.x-dev
Status: Reviewed & tested by the community » Fixed

Cherry-picked to 8.9.x and 9.0.x as a low-risk bug fix that helps contrib and custom.

  • alexpott committed 3dfa560 on 9.0.x
    Issue #3171743 by chr.fritsch, paulocs, Berdir, phenaproxima: Not...

  • alexpott committed 3930613 on 8.9.x
    Issue #3171743 by chr.fritsch, paulocs, Berdir, phenaproxima: Not...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.