Closed (fixed)
Project:
Drupal core
Version:
8.6.x-dev
Component:
media system
Priority:
Major
Category:
Bug report
Assigned:
Issue tags:
Reporter:
Created:
27 Jul 2018 at 12:46 UTC
Updated:
22 May 2019 at 08:00 UTC
Jump to comment: Most recent, Most recent file

Comments
Comment #2
bkosborneI'll take a look
Comment #3
bkosborneThis was an easy fix, but need to add a test. I'm taking a look at writing the test as well.
Comment #4
amateescu commentedWe should do this check on
FieldStorageDefinitionInterface, instead of its config implementation :)Comment #5
phenaproximaThanks, @bkosborne! Running testbot anyway, and tagging for test coverage.
Comment #6
phenaproximaIt's worth mentioning that the Mink driver used by the tests doesn't support multiple file uploads (at all), so we may need to manually test this. If it can be reproduced by uploading a single file into an unlimited-cardinality field, though, let's do that.
Comment #7
bkosborneYes it can be reproduced by uploading a single file. Test getting there.
Comment #8
bkosborneDidn't run this test locally yet, but maybe I'll get lucky. Also addressed #4
Comment #9
phenaproximaTests are written; removing tag.
Comment #11
bkosborneVery frustrating trying to get local testing environment setup =/. I have it going with PHPUnit. The error I'm currently getting is tough to figure out:
I think I followed everything in the guide but this is blocking me.
Sorry all, if anyone can maybe assist with local setup, ping me in #media, but I have to move on to some other work for the moment.
Comment #12
samuel.mortensonWorking on this.
Comment #13
samuel.mortensonWow, this bug was hard!
First, the "Unlimited media" field in the test module does not allow you to select any media types that use the file/image source. As a result, I would expect that without config changes the "Add media" button shouldn't even be present. Unfortunately, because of #2956747: Pass query parameters to the route access check query parameters used to build a
Drupal\Core\Urlobject are not passed when determining access, so the "Add media" button showed up on every instance of the Media library widget _if_ the user had access to create _any_ media. This only affected the "Add media" button in the field widget, which is why I didn't catch this before.I resolved this problem by calling the form's access method directly in the field widget, which we can remove when #2956747: Pass query parameters to the route access check is closed. Alternatively, the work done in #2987924: Define an API for finding media types based on an arbitrary value could also be used by the field widget to determine if the current user has access to create any media allowed by the field that uses a file source. So we have at least two paths forward for this temporary fix.
I also added test coverage for the above.
Once that resolved, I could actually fix the relevant test failure here, which I did by letting the "Unlimited media" reference a media type that used the file source.
😅All done, phew!
Comment #14
phenaproximaWhat a tricky bug! Thanks for chasing that down. I guess we'll have to try and accelerate #2987924: Define an API for finding media types based on an arbitrary value, since I imagine it's a lot easier to fix things in Media than in the routing system.
Comment #16
samuel.mortensonFixed config bug in test.
Comment #17
geek-merlin@samuel.mortenson 💪!
Comment #18
chr.fritschI am wondering if the "Add access" should also respect the "Create referenced entities if they don't already exist" setting from the field definition.
Could we test the upload of two or three images here?
Comment #19
samuel.mortenson@chrfritsch The handler settings are sadly tied to the Entity Reference Autocomplete widget, and don't make sense for other widgets. "Create referenced entities if they don't already exist" for instance also reveals the "Store new items in" option, which determines what bundle auto-created entities are in. Since this widget allows you to create Media for any of the target bundles that use a file source, this setting wouldn't apply.
"View used to select the entities" similarly seems like a good setting for the library, but doesn't make sense here either - it just executes the view and returns all the entity labels to the entity reference widget.
I almost think that what we need is a custom handler with settings specific to the Media Library, or a message that informs users that handler settings don't really apply here. We should open a new issue for this I think.
We can't test multiple uploads. :-( It's a limitation of the driver as far as I know, which is a shame for this use case.
Comment #20
phenaproximaI've read the patch a few times now, and the problem makes sense (as does the fix). It's too bad we have to place these kinda icky temporary hacks in the widget to deal with this, but there's no other option in the short term. Good thing the media library is experimental!
RTBC once green on all backends.
Comment #21
phenaproximaRe-titling for clarity.
Comment #22
xjmRetitling to sound less like an access bypass. :)
Comment #23
mallezieNot sure if it's exactly the same but in https://www.drupal.org/project/drupal/issues/2894193 there's a test (credits to vaplas) to upload multiple files. Not sure if this could be used here.
Comment #24
alexpottI've confirmed the added tests fail as expected by the fix is not included:
I've also confirmed by watching the tests run in chromedriver that the fixed behaviour works as expected.
Comment #25
alexpottFortunately target_bundles is always set because if not this would fail bad - see https://3v4l.org/Cpicf
Comment #26
amateescu commentedI think it's worth noting that the
target_bundlessetting of the ER field has three states:- NULL: all bundles are referenceable
- []: no bundle is referenceable
- ['some_bundle']: only
some_bundleis referenceableThis is documented in
\Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection::defaultConfiguration, and maybe some logic of this patch needs to be updated based on this information.Comment #27
alexpottThanks for the review @amateescu. I think that the current patch doesn't make anything worse. It just might not be a complete fix for all possible entity reference field settings. Therefore I think we should file a follow-up to add tests to ensure the three possible states of target_bundles work as expected.
Committed and pushed 057b54e03f to 8.7.x and 1dbb94162f to 8.6.x. Thanks!
Comment #30
samuel.mortensonThanks @amateescu - I opened #2989503: Add tests to prove that the media library widget works when target_bundles is NULL to address this. What's funny about that docblock is that in practice target_bundles can never be NULL or an empty array - it's a required field! If you got to configure a field you won't be able to not select a bundle. We should still handle this "un-configured" case.
Comment #31
samuel.mortensonWe missed something here - the input element itself also needs to allow for multiple uploads. This patch needs a quick review and commit, if anyone has time.
Comment #32
phenaproximaMarking for manual testing since Mink doesn't support multiple file uploads.
Comment #33
phenaproximaGave this a quick manual test. It worked exactly as advertised -- the file input accepts multiple files at once, if more can be accepted by the field. Let's get 'er in.
Comment #34
effulgentsia commentedCould an automated test be added that just asserts that the input element has the multiple attribute? And perhaps then an @todo for actually testing the multiple upload once https://github.com/minkphp/Mink/issues/358 is fixed?
Comment #35
samuel.mortensonGood call @effulgentsia, let's do that.
Comment #36
phenaproximaYup, good call. Everything green, let's do it.
Comment #39
effulgentsia commentedPushed to 8.7.x and 8.6.x.
Comment #41
ravi shankar karnati commentedAcquia lighting (8.x-4.000) and Drupal 7.1, issue not fixed with the above mentioned patches. Thanks.