function ViewsLocalTask::getDerivativeDefinitions

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

Overrides DeriverBase::getDerivativeDefinitions

File

core/modules/views/src/Plugin/Derivative/ViewsLocalTask.php, line 69

Class

ViewsLocalTask
Provides local task definitions for all views configured as local tasks.

Namespace

Drupal\views\Plugin\Derivative

Code

public function getDerivativeDefinitions($base_plugin_definition) {
    $this->derivatives = [];
    $view_route_names = $this->state
        ->get('views.view_route_names');
    foreach ($this->getApplicableMenuViews() as $pair) {
        
        /** @var $executable \Drupal\views\ViewExecutable */
        list($view_id, $display_id) = $pair;
        $executable = $this->viewStorage
            ->load($view_id)
            ->getExecutable();
        $executable->setDisplay($display_id);
        $menu = $executable->display_handler
            ->getOption('menu');
        if (in_array($menu['type'], [
            'tab',
            'default tab',
        ])) {
            $plugin_id = 'view.' . $executable->storage
                ->id() . '.' . $display_id;
            $route_name = $view_route_names[$executable->storage
                ->id() . '.' . $display_id];
            // Don't add a local task for views which override existing routes.
            // @todo Alternative it could just change the existing entry.
            if ($route_name != $plugin_id) {
                continue;
            }
            $this->derivatives[$plugin_id] = [
                'route_name' => $route_name,
                'weight' => $menu['weight'],
                'title' => $menu['title'],
            ] + $base_plugin_definition;
            // Default local tasks have themselves as root tab.
            if ($menu['type'] == 'default tab') {
                $this->derivatives[$plugin_id]['base_route'] = $route_name;
            }
        }
    }
    return $this->derivatives;
}

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