Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
.
Comment | File | Size | Author |
---|---|---|---|
#16 | 3171743-16.patch | 5.2 KB | paulocs |
#16 | interdiff-13-16.txt | 626 bytes | paulocs |
#13 | 3171743-13.patch | 5.19 KB | chr.fritsch |
#8 | 3171743-5.patch | 1.6 KB | chr.fritsch |
#4 | 3171743-4.patch | 4.63 KB | chr.fritsch |
Comments
Comment #2
chr.fritschHere is a patch.
Comment #4
chr.fritschRemoving the prepending slash
Comment #5
BerdirI'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?
Comment #6
chr.fritschIt's not nice, but it doesn't harm IMHO.
I already thought about that, but that's really bad DX and I don't like that.
Comment #7
BerdirWell, 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.
Comment #8
chr.fritschYes, that's possible.
Comment #9
phenaproximaI 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?
Comment #10
chr.fritschIn
testMediaTypeAddForm
we already test that the forms are set. I think that's ok.Comment #11
phenaproximaFair :) Looks legit to me, then!
Comment #12
alexpottI think we should have a kernel test that we can override them otherwise it'd be easy for this to regress.
Comment #13
chr.fritschAdded a test to ensure a different add form is used.
Comment #15
chr.fritschRandom fail
Comment #16
paulocsThat'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.
Comment #17
volkerk CreditAttribution: volkerk at Thunder commentedThe test does work. Looks good to me.
Comment #18
alexpottCommitted 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
Comment #20
alexpottCherry-picked to 8.9.x and 9.0.x as a low-risk bug fix that helps contrib and custom.