clean install

This commit is contained in:
2024-12-10 15:08:16 +01:00
commit e14eb2d8fd
31193 changed files with 3555714 additions and 0 deletions

View File

@@ -0,0 +1,165 @@
<?php
namespace Drupal\gin_toolbar\Menu;
use Drupal\Core\Menu\MenuActiveTrail;
/**
* Handles the active trail.
*/
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();
// Content.
if (in_array($route_name, [
'system.admin_content',
'node.add_page',
'entity.node.canonical',
'entity.node.edit_form',
])) {
$link = $this->getLinkByRoutes($menu_name, [
[$route_name, $route_params],
['system.admin_content', []],
]);
}
// Create Content.
if ($route_name === 'node.add') {
$link = $this->getLinkByRoutes($menu_name, [
[$route_name, $route_params],
['node.add_page', []],
['system.admin_content', []],
]);
}
// Media.
if (in_array($route_name, [
'view.media_library.page',
'entity.media.collection',
'entity.media.add_page',
'entity.media.add_form',
])) {
$link = $this->getLinkByRoutes($menu_name, [
[$route_name, $route_params],
['entity.media.collection', []],
]);
}
// Create Media.
if ($route_name === 'entity.media.add_form') {
$link = $this->getLinkByRoutes($menu_name, [
[$route_name, $route_params],
['entity.media.add_page', []],
['entity.media.collection', []],
]);
}
// Files.
if ($route_name === 'view.files.page_1') {
$link = $this->getLinkByRoutes($menu_name, [
[$route_name, $route_params],
['view.files.page_1 ', []],
]);
}
// Blocks.
if ($route_name === 'entity.block_content.collection') {
$link = $this->getLinkByRoutes($menu_name, [
[$route_name, $route_params],
['entity.block_content.collection', []],
]);
}
// User.
if (in_array($route_name, [
'entity.user.collection',
'user.role.settings',
])) {
$link = $this->getLinkByRoutes($menu_name, [
[$route_name, $route_params],
['entity.user.collection', []],
]);
}
// Reports.
if (in_array($route_name, [
'dblog.overview',
'dblog.access_denied',
'dblog.page_not_found',
'dblog.search',
])) {
$link = $this->getLinkByRoutes($menu_name, [
[$route_name, $route_params],
['system.admin_reports', []],
]);
}
// Configuration.
if (in_array($route_name, [
'system.admin_config',
'devel.admin_settings',
])) {
$link = $this->getLinkByRoutes($menu_name, [
[$route_name, $route_params],
['system.admin_config', []],
]);
}
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;
}
}

View File

@@ -0,0 +1,68 @@
<?php
namespace Drupal\gin_toolbar\Render\Element;
use Drupal\Core\Menu\MenuTreeParameters;
use Drupal\Core\Security\TrustedCallbackInterface;
/**
* Adds active trail to trail.
*
* * @package Drupal\gin_toolbar\Render\Element.
*/
class GinToolbar implements TrustedCallbackInterface {
/**
* {@inheritdoc}
*/
public static function trustedCallbacks() {
return ['preRenderTray'];
}
/**
* Renders the toolbar's administration tray.
*
* This is a clone of core's toolbar_prerender_toolbar_administration_tray()
* function, which adds active trail information and which uses setMaxDepth(4)
* instead of setTopLevelOnly() in case the Admin Toolbar module is installed.
*
* @param array $build
* A renderable array.
*
* @return array
* The updated renderable array.
*
* @see toolbar_prerender_toolbar_administration_tray()
*/
public static function preRenderTray(array $build) {
$menu_tree = \Drupal::service('toolbar.menu_tree');
$activeTrail = \Drupal::service('gin_toolbar.active_trail')
->getActiveTrailIds('admin');
$parameters = (new MenuTreeParameters())
->setActiveTrail($activeTrail)
->setRoot('system.admin')
->excludeRoot()
->setTopLevelOnly()
->onlyEnabledLinks();
if (\Drupal::moduleHandler()->moduleExists('admin_toolbar')) {
$admin_toolbar_settings = \Drupal::config('admin_toolbar.settings');
$max_depth = $admin_toolbar_settings->get('menu_depth') ?? 4;
$parameters->setMaxDepth($max_depth);
}
$tree = $menu_tree->load('admin', $parameters);
$manipulators = [
['callable' => 'menu.default_tree_manipulators:checkAccess'],
['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
['callable' => 'gin_toolbar_tools_menu_navigation_links'],
];
$tree = $menu_tree->transform($tree, $manipulators);
$build['administration_menu'] = $menu_tree->build($tree);
$build['#cache']['contexts'][] = 'route.menu_active_trails:admin';
return $build;
}
}