You are here

public function ViewsMenuLink::loadView in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/src/Plugin/Menu/ViewsMenuLink.php \Drupal\views\Plugin\Menu\ViewsMenuLink::loadView()
  2. 9 core/modules/views/src/Plugin/Menu/ViewsMenuLink.php \Drupal\views\Plugin\Menu\ViewsMenuLink::loadView()

Initializes the proper view.

Return value

\Drupal\views\ViewExecutable The view executable.

File

core/modules/views/src/Plugin/Menu/ViewsMenuLink.php, line 92

Class

ViewsMenuLink
Defines menu links provided by views.

Namespace

Drupal\views\Plugin\Menu

Code

public function loadView() {
  if (empty($this->view)) {
    $metadata = $this
      ->getMetaData();
    $view_id = $metadata['view_id'];
    $display_id = $metadata['display_id'];
    $view_entity = $this->entityTypeManager
      ->getStorage('view')
      ->load($view_id);
    $view = $this->viewExecutableFactory
      ->get($view_entity);
    $view
      ->setDisplay($display_id);
    $view
      ->initDisplay();
    $this->view = $view;
  }
  return $this->view;
}