interface MediaLibraryOpenerInterface (View source)

Defines an interface for media library openers.

Media library opener services allow modules to check access to the media library selection dialog and respond to selections. Example use cases that require different handling:

  • when used in an entity reference field widget;
  • when used in a text editor.

Openers that require additional parameters or metadata should retrieve them from the MediaLibraryState object.

Methods

checkAccess(MediaLibraryState $state, AccountInterface $account)

Checks media library access.

getSelectionResponse(MediaLibraryState $state, array $selected_ids)

Generates a response after selecting media items in the media library.

Details

AccessResultInterface checkAccess(MediaLibraryState $state, AccountInterface $account)

Checks media library access.

Parameters

MediaLibraryState $state

The media library.

AccountInterface $account

The user for which to check access.

Return Value

AccessResultInterface

The access result.

See also

https://www.drupal.org/project/drupal/issues/3038254

AjaxResponse getSelectionResponse(MediaLibraryState $state, array $selected_ids)

Generates a response after selecting media items in the media library.

Parameters

MediaLibraryState $state

The state the media library was in at the time of selection, allowing the response to be customized based on that state.

array $selected_ids

The IDs of the selected media items.

Return Value

AjaxResponse

The response to update the page after selecting media.