Problem/Motivation
media_library.api.php states that while the media library itself is very opinionated, the openers act as a bridge between the system and the library: "An opener is a "bridge" between the opinionated media library modal dialog and whatever is consuming it"
Yet when you look into MediaLibraryFieldWidgetOpener, it is still very opinionated about where it's being used when it comes to access. This has lead to several bug reports so far and it's likely to keep leading to bug reports as implementing code changes on the access level because the opener should frankly not be assuming anything about access checks. Some examples:
- #3197416: MediaLibraryFieldWidgetOpener::checkAccess denies access when modifying field values on a translated entity revision
- #3071489: Incorrect Access Check on Media Library
- #3124302: The media library should perform access checks against the revision of the entity being edited
Proposed resolution
Simply remove the access checks from the opener. If you're on an entity form using the media library, you obviously have access to be on said form. The media library should then only check for access to the media library. If we stop double-confirming whether you should actually be on the form, all of these bug reports go away.
Remaining tasks
Remove the access checking logic altogether.
API changes
Remove the access checking logic altogether.
Comments
Comment #2
zenimagine commentedComment #3
jeffm2001 commentedI ran into an issue around this as well, and while I tend to agree it's too opinionated, I did find the original discussion of why these checks were added. It seems like useful context to have, if nothing else.
#3038254: Delegate media library access to the "thing" that opened the library starting around comment 62
Comment #5
erik.erskine commentedWe've come up against two cases where a user should quite legitimately be able to use the media library but does not have the create access: group and layout builder.
I am interested in why
checkAccessexists at all. As far as I can tell, it doesn't add anything useful. Especially given that whileMediaLibraryFieldWidgetOpenerconsiders the entity/bundle you're working on,MediaLibraryEditorOpener(used for ckeditor-added media) does not, and in fact does not even know what the entity/bundle are.As a workaround, we have created the Media library unrestricted access sandbox module. It defines a unrestricted access to the media library permission and bypasses the
createAccesscheck if the user has that permission. It's one stop short of the change this issue proposes, but could be a useful workaround in the meantime.