public function LinkitMediaLibraryEditorOpener::getSelectionResponse in Linkit Media Library 1.0.x
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
- src/
LinkitMediaLibraryEditorOpener.php, line 68
Class
- LinkitMediaLibraryEditorOpener
- The media library opener for text editors.
Namespace
Drupal\linkit_media_libraryCode
public function getSelectionResponse(MediaLibraryState $state, array $selected_ids) {
/** @var \Drupal\media\MediaInterface $selected_media */
$selected_media = $this->mediaStorage
->load(reset($selected_ids));
$response = new AjaxResponse();
$values = [
'attributes' => [
'data-entity-type' => 'media',
'data-entity-substitution' => 'media',
'data-entity-uuid' => $selected_media
->uuid(),
'href' => '/media/' . $selected_media
->id(),
'target' => '_blank',
],
];
$response
->addCommand(new EditorDialogSave($values));
return $response;
}