You are here

public function MediaLibraryEditorOpener::getSelectionResponse in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/media_library/src/MediaLibraryEditorOpener.php \Drupal\media_library\MediaLibraryEditorOpener::getSelectionResponse()

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

Parameters

\Drupal\media_library\MediaLibraryState $state: The state the media library was in at the time of selection, allowing the response to be customized based on that state.

int[] $selected_ids: The IDs of the selected media items.

Return value

\Drupal\Core\Ajax\AjaxResponse The response to update the page after selecting media.

Overrides MediaLibraryOpenerInterface::getSelectionResponse

File

core/modules/media_library/src/MediaLibraryEditorOpener.php, line 65

Class

MediaLibraryEditorOpener
The media library opener for text editors.

Namespace

Drupal\media_library

Code

public function getSelectionResponse(MediaLibraryState $state, array $selected_ids) {
  $selected_media = $this->mediaStorage
    ->load(reset($selected_ids));
  $response = new AjaxResponse();
  $values = [
    'attributes' => [
      'data-entity-type' => 'media',
      'data-entity-uuid' => $selected_media
        ->uuid(),
      'data-align' => 'center',
    ],
  ];
  $response
    ->addCommand(new EditorDialogSave($values));
  return $response;
}