Closed (works as designed)
Project:
Drupal core
Version:
9.3.x-dev
Component:
media system
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
16 Aug 2018 at 23:37 UTC
Updated:
20 Jul 2021 at 18:17 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
stefan.kornHow about this patch
Comment #3
stefan.kornComment #4
geek-merlinHey, nice work! I did not test this, but code looks straightforward.
For the constants and UI texts though, i'd suggest using positive wording like "Allow adding new and using existing media" / ALLOW_NEW_AND_EXISTING.
Comment #5
dwwNice to see this feature, and a patch to get it close. Thanks!
+1 to the suggestions in #4. The patch and UI is a bit hard to make sense of as-is.
This also seems clumsy. Not entirely sure the best solution, but maybe we don't need the 'Add and attach button settings: " part of this at all. Just have the summary include the (positively worded) version of which button(s) are visible?
Cheers,
-Derek
Comment #7
taivu commentedthis patch could not be applied after 8.7.1 update.
Comment #8
chr.fritschI am working on this
Comment #9
chr.fritschAfter talking to @phenaproxima on slack, we agreed that this issue is quite outdated because it is based on the media library design of D8.6.
Since then the library evolved a lot. So we have to re-think this issue.
We agreed that "only use existing" is still valid. But "only upload" is against how the library is designed nowadays.
So we want to add a field widget config setting to choose the "only use existing" behavior.
Comment #10
chr.fritschHere is a patch that implements #9
Comment #11
phenaproximaThanks, @chr.fritsch! However...
I don't think the setting is something we should be propagating in the MediaLibraryState object. It's a field-level setting, and it's not going to change while a user interacts with the library. A preferable approach, I think, would be for MediaLibraryWidget to deny access to the add form returned from the UI builder, based on the setting. Something like this:
Also tagging for tests.
Comment #12
chr.fritschThanks for the quick response. Media Library is still new for me.
So here is the next approach 😁
I will look into the tests next week.
Comment #14
wim leersComment #18
phenaproximaTransferring credit from duplicate issue #3085532: Media Library Always allows creation of new references.
Comment #19
andreyjan commentedThe last patch is not applying to 8.9. Rerolled the patch and also updated settings summary with the new setting.
Working on the tests.
Comment #20
andreyjan commentedHere's the patch with tests for this functionality.
Comment #22
andreyjan commentedAttempt to fix failing tests.
Comment #23
andreyjan commentedComment #25
seanbI think we should try to pass this to the UI builder via the library state (maybe through the opener parameters) and solve this in the UI builder.
Comment #29
sakthivel m commentedComment #30
sakthivel m commented#30 Please review the Patch
Comment #32
vsujeetkumar commented@Sakthivel M if #30 is the reroll then changes has been done in the wrong file(core.entity_view_display.node.basic_page.default.yml).
Re-roll patch given, Please have a look.
Comment #34
phenaproximaI think I see another way to accomplish this. It would be more complex, but also more robust, and would not require us to add a setting.
Right now, the media library asks the entity system if the user can create media of the current type, and that's how it determines whether the "add new media" form should be shown. This happens in
\Drupal\media_library\MediaLibraryUiBuilder::buildMediaTypeAddForm():As it turns out, entity access control handlers support passing an arbitrary $context array to
createAccess(), as per https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21....I propose that we simply pass the media library state object to the access control handler, and let the other modules in the system figure out access. This provides a great deal of flexibility to implement this sort of behavior using hooks like
hook_ENTITY_TYPE_create_access(), whilst keeping Media Library's functionality small and well-scoped.I'm going to implement this in another branch of the issue fork, so that we have a proof of concept. But to me, this approach would be very much in keeping with Media Library's philosophy of keeping things as simple as possible out-of-the-box.
Comment #36
alexpottI think that the current implementation in HEAD is correct. If the user has the ability to create media items we should allow that. I think most use-cases can be achieved with roles and permissions already. If we want to add additional context for very use-case specific cases to the create access method then @phenaproxima's MR makes sense.
If someone wants a special widget with additional settings or that leverage the new context information then that can go in contrib.
Comment #37
phenaproximaOpened #3224530: Pass the media library state object to createAccess() to make the
$contextchange in core, so that we can close this issue in favor of a contrib/custom solution.Comment #38
seanb+1 for passing the media library state to createAccess() so we could use proper access to show/hide the form. This should allow enough flexibility for contrib to add a third party setting and an access hook to implement this.
Maybe this could be added to something like https://www.drupal.org/project/media_library_extras for now?
Comment #39
phenaproximaYes, once this is in core that's exactly where I think it would make sense to put it.
Since I've opened #3224530: Pass the media library state object to createAccess(), I think we have discussed this issue enough. I'm closing this out as "works as designed". For reference, once that other issue lands (probably in 9.3.x and up only, for the record), this is what you could put into your module to cut off access to the "add new media" part of the media library:
Obviously you could also implement more complicated logic for more exotic use cases, too.