class GinToolbarActiveTrail in Gin Toolbar 8
Class GinToolbarActiveTrail.
@package Drupal\gin_toolbar\Menu
Hierarchy
- class \Drupal\Core\Cache\CacheCollector implements CacheCollectorInterface, DestructableInterface
- class \Drupal\Core\Menu\MenuActiveTrail implements MenuActiveTrailInterface
- class \Drupal\gin_toolbar\Menu\GinToolbarActiveTrail
- class \Drupal\Core\Menu\MenuActiveTrail implements MenuActiveTrailInterface
Expanded class hierarchy of GinToolbarActiveTrail
1 string reference to 'GinToolbarActiveTrail'
1 service uses GinToolbarActiveTrail
File
- src/
Menu/ GinToolbarActiveTrail.php, line 12
Namespace
Drupal\gin_toolbar\MenuView source
class GinToolbarActiveTrail extends MenuActiveTrail {
/**
* {@inheritdoc}
*
* Change the active trail for node add/edit/view routes.
*/
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;
}
/**
* {@inheritdoc}
*
* The active trail logic is different here, so the active trails should be
* cached separately.
*/
protected function getCid() {
if (!isset($this->cid)) {
$this->cid = 'gin-toolbar-' . parent::getCid();
}
return $this->cid;
}
/**
* Get a possible link to base the active trail on.
*
* @param string $menu_name
* The name of the menu.
* @param array $routes
* An array of route name & route params combinations in order of relevance.
*/
protected function getLinkByRoutes(string $menu_name, array $routes) {
foreach ($routes as $route) {
[
$route_name,
$route_params,
] = $route;
$links = $this->menuLinkManager
->loadLinksByRoute($route_name, $route_params, $menu_name);
foreach ($links as $link) {
if (!empty($link
->getParent())) {
return $link;
}
}
}
return NULL;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheCollector:: |
protected | property | The cache backend that should be used. | 1 |
CacheCollector:: |
protected | property | Stores the cache creation time. | |
CacheCollector:: |
protected | property | Flag that indicates of the cache has been invalidated. | |
CacheCollector:: |
protected | property | Indicates if the collected cache was already loaded. | |
CacheCollector:: |
protected | property | The cache id that is used for the cache entry. | |
CacheCollector:: |
protected | property | An array of keys to add to the cache on service termination. | |
CacheCollector:: |
protected | property | An array of keys to remove from the cache on service termination. | |
CacheCollector:: |
protected | property | The lock backend that should be used. | 1 |
CacheCollector:: |
protected | property | Storage for the data itself. | |
CacheCollector:: |
protected | property | A list of tags that are used for the cache entry. | |
CacheCollector:: |
public | function |
Clears the collected cache entry. Overrides CacheCollectorInterface:: |
1 |
CacheCollector:: |
public | function |
Deletes the element. Overrides CacheCollectorInterface:: |
|
CacheCollector:: |
public | function |
Performs destruct operations. Overrides DestructableInterface:: |
|
CacheCollector:: |
public | function |
Gets value from the cache. Overrides CacheCollectorInterface:: |
2 |
CacheCollector:: |
public | function |
Returns whether data exists for this key. Overrides CacheCollectorInterface:: |
1 |
CacheCollector:: |
protected | function | Invalidate the cache. | |
CacheCollector:: |
protected | function | Loads the cache if not already done. | 1 |
CacheCollector:: |
protected | function | Normalizes a cache ID in order to comply with database limitations. | |
CacheCollector:: |
protected | function | Flags an offset value to be written to the persistent cache. | |
CacheCollector:: |
public | function |
Resets the local cache. Overrides CacheCollectorInterface:: |
1 |
CacheCollector:: |
public | function |
Implements \Drupal\Core\Cache\CacheCollectorInterface::set(). Overrides CacheCollectorInterface:: |
1 |
CacheCollector:: |
protected | function | Writes a value to the persistent cache immediately. | 1 |
GinToolbarActiveTrail:: |
protected | function |
Change the active trail for node add/edit/view routes. Overrides MenuActiveTrail:: |
|
GinToolbarActiveTrail:: |
protected | function |
The active trail logic is different here, so the active trails should be
cached separately. Overrides MenuActiveTrail:: |
|
GinToolbarActiveTrail:: |
protected | function | Get a possible link to base the active trail on. | |
MenuActiveTrail:: |
protected | property | The menu link plugin manager. | |
MenuActiveTrail:: |
protected | property | The route match object for the current page. | |
MenuActiveTrail:: |
public | function |
Fetches a menu link which matches the route name, parameters and menu name. Overrides MenuActiveTrailInterface:: |
|
MenuActiveTrail:: |
public | function |
This implementation caches all active trail IDs per route match for *all*
menus whose active trails are calculated on that page. This ensures 1 cache
get for all active trails per page load, rather than N. Overrides MenuActiveTrailInterface:: |
|
MenuActiveTrail:: |
protected | function |
Overrides CacheCollector:: |
|
MenuActiveTrail:: |
public | function |
Constructs a \Drupal\Core\Menu\MenuActiveTrail object. Overrides CacheCollector:: |