function MediaLibraryEditorOpener::getSelectionResponse

Same name and namespace in other branches
  1. 8.9.x core/modules/media_library/src/MediaLibraryEditorOpener.php \Drupal\media_library\MediaLibraryEditorOpener::getSelectionResponse()
  2. 10 core/modules/media_library/src/MediaLibraryEditorOpener.php \Drupal\media_library\MediaLibraryEditorOpener::getSelectionResponse()
  3. 11.x 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 63

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.