You are here

protected function GinToolbarActiveTrail::doGetActiveTrailIds in Gin Toolbar 8

Change the active trail for node add/edit/view routes.

Overrides MenuActiveTrail::doGetActiveTrailIds

File

src/Menu/GinToolbarActiveTrail.php, line 19

Class

GinToolbarActiveTrail
Class GinToolbarActiveTrail.

Namespace

Drupal\gin_toolbar\Menu

Code

protected function doGetActiveTrailIds($menu_name) {
  $route_name = $this->routeMatch
    ->getRouteName();
  $route_params = $this->routeMatch
    ->getRawParameters()
    ->all();
  if ($route_name === 'node.add') {
    $link = $this
      ->getLinkByRoutes($menu_name, [
      [
        $route_name,
        $route_params,
      ],
      [
        'node.add_page',
        [],
      ],
      [
        'system.admin_content',
        [],
      ],
    ]);
  }
  if ($route_name === 'node.add_page') {
    $link = $this
      ->getLinkByRoutes($menu_name, [
      [
        $route_name,
        $route_params,
      ],
      [
        'system.admin_content',
        [],
      ],
    ]);
  }
  if (in_array($route_name, [
    'entity.node.canonical',
    'entity.node.edit_form',
  ])) {
    $link = $this
      ->getLinkByRoutes($menu_name, [
      [
        $route_name,
        $route_params,
      ],
      [
        'system.admin_content',
        [],
      ],
    ]);
  }
  if (!isset($link)) {
    return parent::doGetActiveTrailIds($menu_name);
  }
  $active_trail = [
    '' => '',
  ];
  if ($parents = $this->menuLinkManager
    ->getParentIds($link
    ->getPluginId())) {
    $active_trail = $parents + $active_trail;
  }
  return $active_trail;
}