function ViewsMenuLink::getDerivativeDefinitions

Same name in other branches
  1. 9 core/modules/views/src/Plugin/Derivative/ViewsMenuLink.php \Drupal\views\Plugin\Derivative\ViewsMenuLink::getDerivativeDefinitions()
  2. 8.9.x core/modules/views/src/Plugin/Derivative/ViewsMenuLink.php \Drupal\views\Plugin\Derivative\ViewsMenuLink::getDerivativeDefinitions()
  3. 10 core/modules/views/src/Plugin/Derivative/ViewsMenuLink.php \Drupal\views\Plugin\Derivative\ViewsMenuLink::getDerivativeDefinitions()

Overrides DeriverBase::getDerivativeDefinitions

File

core/modules/views/src/Plugin/Derivative/ViewsMenuLink.php, line 48

Class

ViewsMenuLink
Provides menu links for Views.

Namespace

Drupal\views\Plugin\Derivative

Code

public function getDerivativeDefinitions($base_plugin_definition) {
    $links = [];
    $views = Views::getApplicableViews('uses_menu_links');
    foreach ($views as $data) {
        [
            $view_id,
            $display_id,
        ] = $data;
        
        /** @var \Drupal\views\ViewExecutable $executable */
        $executable = $this->viewStorage
            ->load($view_id)
            ->getExecutable();
        $executable->initDisplay();
        $display = $executable->displayHandlers
            ->get($display_id);
        if ($display instanceof DisplayMenuInterface && ($result = $display->getMenuLinks())) {
            foreach ($result as $link_id => $link) {
                $links[$link_id] = $link + $base_plugin_definition;
            }
        }
    }
    return $links;
}

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