clean install

This commit is contained in:
matze committed 2024-12-10 15:08:16 +01:00
commit e14eb2d8fd
31193 files changed
+3555714

No files matched your search

@@ -0,0 +1,85 @@
<?php
namespace Drupal\admin_toolbar\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class AdminToolbarSettingsForm. The config form for the admin_toolbar module.
*
* @package Drupal\admin_toolbar\Form
*/
class AdminToolbarSettingsForm extends ConfigFormBase {
/**
* The cache menu instance.
*
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $cacheMenu;
/**
* The menu link manager instance.
*
* @var \Drupal\Core\Menu\MenuLinkManagerInterface
*/
protected $menuLinkManager;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
$instance = parent::create($container);
$instance->cacheMenu = $container->get('cache.menu');
$instance->menuLinkManager = $container->get('plugin.manager.menu.link');
return $instance;
}
/**
* {@inheritDoc}
*/
protected function getEditableConfigNames() {
return [
'admin_toolbar.settings',
];
}
/**
* {@inheritDoc}
*/
public function getFormId() {
return 'admin_toolbar_settings';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('admin_toolbar.settings');
$depth_values = range(1, 9);
$form['menu_depth'] = [
'#type' => 'select',
'#title' => $this->t('Menu depth'),
'#description' => $this->t('Maximal depth of displayed menu.'),
'#default_value' => $config->get('menu_depth'),
'#options' => array_combine($depth_values, $depth_values),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->config('admin_toolbar.settings')
->set('menu_depth', $form_state->getValue('menu_depth'))
->save();
parent::submitForm($form, $form_state);
$this->cacheMenu->invalidateAll();
$this->menuLinkManager->rebuild();
}
}
@@ -0,0 +1,52 @@
<?php
namespace Drupal\admin_toolbar\Render\Element;
use Drupal\Core\Menu\MenuTreeParameters;
use Drupal\Core\Security\TrustedCallbackInterface;
/**
* Render element element for AdminToolbar.
*
* @package Drupal\admin_toolbar\Render\Element
*/
class AdminToolbar 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 uses setMaxDepth(4) instead of setTopLevelOnly().
*
* @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');
$parameters = new MenuTreeParameters();
$max_depth = \Drupal::config('admin_toolbar.settings')->get('menu_depth');
$parameters->setRoot('system.admin')->excludeRoot()->setMaxDepth($max_depth)->onlyEnabledLinks();
$tree = $menu_tree->load('admin', $parameters);
$manipulators = [
['callable' => 'menu.default_tree_manipulators:checkAccess'],
['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
['callable' => 'toolbar_tools_menu_navigation_links'],
];
$tree = $menu_tree->transform($tree, $manipulators);
$build['administration_menu'] = $menu_tree->build($tree);
return $build;
}
}