public function MediaLibraryUiBuilder::buildUi in Drupal 9
Same name and namespace in other branches
- 8 core/modules/media_library/src/MediaLibraryUiBuilder.php \Drupal\media_library\MediaLibraryUiBuilder::buildUi()
Build the media library UI.
Parameters
\Drupal\media_library\MediaLibraryState $state: (optional) The current state of the media library, derived from the current request.
Return value
array The render array for the media library.
File
- core/
modules/ media_library/ src/ MediaLibraryUiBuilder.php, line 109
Class
- MediaLibraryUiBuilder
- Service which builds the media library.
Namespace
Drupal\media_libraryCode
public function buildUi(MediaLibraryState $state = NULL) {
if (!$state) {
$state = MediaLibraryState::fromRequest($this->request);
}
// When navigating to a media type through the vertical tabs, we only want
// to load the changed library content. This is not only more efficient, but
// also provides a more accessible user experience for screen readers.
if ($state
->get('media_library_content') === '1') {
return $this
->buildLibraryContent($state);
}
else {
return [
'#theme' => 'media_library_wrapper',
'#attributes' => [
'id' => 'media-library-wrapper',
],
'menu' => $this
->buildMediaTypeMenu($state),
'content' => $this
->buildLibraryContent($state),
// Attach the JavaScript for the media library UI. The number of
// available slots needs to be added to make sure users can't select
// more items than allowed.
'#attached' => [
'library' => [
'media_library/ui',
],
'drupalSettings' => [
'media_library' => [
'selection_remaining' => $state
->getAvailableSlots(),
],
],
],
];
}
}