You are here

protected function MediaLibraryUiBuilder::buildMediaLibraryView in Drupal 8

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

Get the media library view.

Parameters

\Drupal\media_library\MediaLibraryState $state: The current state of the media library, derived from the current request.

Return value

array The render array for the media library view.

1 call to MediaLibraryUiBuilder::buildMediaLibraryView()
MediaLibraryUiBuilder::buildLibraryContent in core/modules/media_library/src/MediaLibraryUiBuilder.php
Build the media library content area.

File

core/modules/media_library/src/MediaLibraryUiBuilder.php, line 325

Class

MediaLibraryUiBuilder
Service which builds the media library.

Namespace

Drupal\media_library

Code

protected function buildMediaLibraryView(MediaLibraryState $state) {

  // @todo Make the view configurable in
  //   https://www.drupal.org/project/drupal/issues/2971209
  $view = $this->entityTypeManager
    ->getStorage('view')
    ->load('media_library');
  $view_executable = $this->viewsExecutableFactory
    ->get($view);
  $display_id = $state
    ->get('views_display_id', 'widget');

  // Make sure the state parameters are set in the request so the view can
  // pass the parameters along in the pager, filters etc.
  $view_request = $view_executable
    ->getRequest();
  $view_request->query
    ->add($state
    ->all());
  $view_executable
    ->setRequest($view_request);
  $args = [
    $state
      ->getSelectedTypeId(),
  ];

  // Make sure the state parameters are set in the request so the view can
  // pass the parameters along in the pager, filters etc.
  $request = $view_executable
    ->getRequest();
  $request->query
    ->add($state
    ->all());
  $view_executable
    ->setRequest($request);
  $view_executable
    ->setDisplay($display_id);
  $view_executable
    ->preExecute($args);
  $view_executable
    ->execute($display_id);
  return $view_executable
    ->buildRenderable($display_id, $args, FALSE);
}