admin_toolbar_tools.module 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. <?php
  2. /**
  3. * @file
  4. * Provides extra menu links for the core drupal toolbar.
  5. */
  6. use Drupal\Core\Routing\RouteMatchInterface;
  7. use Drupal\Core\Url;
  8. /**
  9. * Implements hook_toolbar().
  10. */
  11. function admin_toolbar_tools_toolbar() {
  12. $items = [];
  13. $items['admin_toolbar_tools'] = [
  14. '#type' => 'toolbar_item',
  15. 'tab' => [
  16. '#type' => 'link',
  17. '#attributes' => [
  18. 'class' => ['toolbar-icon', 'toolbar-icon-admin-toolbar-tools-help'],
  19. ],
  20. ],
  21. '#attached' => ['library' => ['admin_toolbar_tools/toolbar.icon']],
  22. ];
  23. return $items;
  24. }
  25. /**
  26. * Implements hook_help().
  27. */
  28. function admin_toolbar_tools_help($route_name, RouteMatchInterface $route_match) {
  29. switch ($route_name) {
  30. case 'help.page.admin_toolbar_tools':
  31. $output = '';
  32. $output .= '<p>';
  33. $output .= t('The Admin Toolbar Extra Tools module comes packaged with the <a href=":admin-toolbar">Admin Toolbar</a> module and adds functionality to it. The additional functionality is accessed thru extra links on the main administration Toolbar. Some links to Admin Toolbar Extra Tools administration pages are located at the bottom of this page.</a>', [':admin-toolbar' => Url::fromRoute('help.page', ['name' => 'admin_toolbar'])->toString()]);
  34. $output .= '</p>';
  35. $output .= '<h3>' . t('Uses') . '</h3>';
  36. $output .= '<p>' . t('To use Admin Toolbar Extra Tools just install it like any other module. There is no other configuration required.') . '</p>';
  37. return $output;
  38. }
  39. }
  40. /**
  41. * Implements hook_menu_links_discovered_alter().
  42. */
  43. function admin_toolbar_tools_menu_links_discovered_alter(&$links) {
  44. $languageManager = \Drupal::languageManager();
  45. $config_override_language = $languageManager->getConfigOverrideLanguage();
  46. $languageManager->setConfigOverrideLanguage($languageManager->getLanguage('en'));
  47. $moduleHandler = \Drupal::moduleHandler();
  48. $entityTypeManager = \Drupal::entityTypeManager();
  49. $routeProvider = \Drupal::service('router.route_provider');
  50. /**
  51. * Determine if a route exists by name.
  52. *
  53. * @param $routeName
  54. * The name of the route to check.
  55. *
  56. * @return bool
  57. * Whether a route with that route name exists.
  58. */
  59. $routeExists = function ($routeName) use ($routeProvider) {
  60. return (count($routeProvider->getRoutesByNames([$routeName])) === 1);
  61. };
  62. $entityTypes = $entityTypeManager->getDefinitions();
  63. $content_entities = [];
  64. foreach ($entityTypes as $key => $entityType) {
  65. if ($entityType->getBundleEntityType() && ($entityType->get('field_ui_base_route') != '')) {
  66. $content_entities[$key] = [
  67. 'content_entity' => $key,
  68. 'content_entity_bundle' => $entityType->getBundleEntityType(),
  69. ];
  70. }
  71. }
  72. // Adding a menu link to clean the Views cache.
  73. if ($moduleHandler->moduleExists('views')) {
  74. $links['admin_toolbar_tools.flush_views'] = [
  75. 'title' => t('Flush views cache'),
  76. 'provider' => 'admin_toolbar_tools',
  77. 'route_name' => 'admin_toolbar_tools.flush_views',
  78. 'menu_name' => 'admin',
  79. 'parent' => 'admin_toolbar_tools.flush',
  80. ];
  81. // Adding a menu link to Files.
  82. if ($moduleHandler->moduleExists('file') && $routeExists('view.files.page_1')) {
  83. $links['admin_toolbar_tools.view.files'] = [
  84. 'title' => t('Files'),
  85. 'provider' => 'admin_toolbar_tools',
  86. 'route_name' => 'view.files.page_1',
  87. 'menu_name' => 'admin',
  88. 'parent' => 'system.admin_content',
  89. ];
  90. }
  91. }
  92. // Adds common links to entities.
  93. foreach ($content_entities as $entities) {
  94. $content_entity_bundle = $entities['content_entity_bundle'];
  95. $content_entity = $entities['content_entity'];
  96. foreach ($entityTypeManager->getStorage($content_entity_bundle)->loadMultiple() as $machine_name => $bundle) {
  97. // Normally, the edit form for the bundle would be its root link.
  98. $content_entity_bundle_root = NULL;
  99. if ($routeExists('entity.' . $content_entity_bundle . '.overview_form')) {
  100. // Some bundles have an overview/list form that make a better root link.
  101. $content_entity_bundle_root = 'entity.' . $content_entity_bundle . '.overview_form.' . $machine_name;
  102. $links[$content_entity_bundle_root] = [
  103. 'title' => t($bundle->label()),
  104. 'provider' => 'admin_toolbar_tools',
  105. 'route_name' => 'entity.' . $content_entity_bundle . '.overview_form',
  106. 'menu_name' => 'admin',
  107. 'parent' => 'entity.' . $content_entity_bundle . '.collection',
  108. 'route_parameters' => [$content_entity_bundle => $machine_name],
  109. ];
  110. }
  111. if ($routeExists('entity.' . $content_entity_bundle . '.edit_form')) {
  112. $key = 'entity.' . $content_entity_bundle . '.edit_form.' . $machine_name;
  113. $links[$key] = [
  114. 'title' => t($bundle->label()),
  115. 'provider' => 'admin_toolbar_tools',
  116. 'route_name' => 'entity.' . $content_entity_bundle . '.edit_form',
  117. 'menu_name' => 'admin',
  118. 'parent' => 'entity.' . $content_entity_bundle . '.collection',
  119. 'route_parameters' => [$content_entity_bundle => $machine_name],
  120. ];
  121. if (empty($content_entity_bundle_root)) {
  122. $content_entity_bundle_root = $key;
  123. }
  124. else {
  125. $links[$key]['parent'] = $content_entity_bundle_root;
  126. $links[$key]['title'] = t('Edit');
  127. }
  128. }
  129. if ($moduleHandler->moduleExists('field_ui')) {
  130. if ($routeExists('entity.' . $content_entity . '.field_ui_fields')) {
  131. $links['entity.' . $content_entity . '.field_ui_fields' . $machine_name] = [
  132. 'title' => t('Manage fields'),
  133. 'provider' => 'admin_toolbar_tools',
  134. 'route_name' => 'entity.' . $content_entity . '.field_ui_fields',
  135. 'menu_name' => 'admin',
  136. 'parent' => $content_entity_bundle_root,
  137. 'route_parameters' => [$content_entity_bundle => $machine_name],
  138. 'weight' => 1,
  139. ];
  140. }
  141. if ($routeExists('entity.entity_form_display.' . $content_entity . '.default')) {
  142. $links['entity.entity_form_display.' . $content_entity . '.default' . $machine_name] = [
  143. 'title' => t('Manage form display'),
  144. 'provider' => 'admin_toolbar_tools',
  145. 'route_name' => 'entity.entity_form_display.' . $content_entity . '.default',
  146. 'menu_name' => 'admin',
  147. 'parent' => $content_entity_bundle_root,
  148. 'route_parameters' => [$content_entity_bundle => $machine_name],
  149. 'weight' => 2,
  150. ];
  151. }
  152. if ($routeExists('entity.entity_view_display.' . $content_entity . '.default')) {
  153. $links['entity.entity_view_display.' . $content_entity . '.default.' . $machine_name] = [
  154. 'title' => t('Manage display'),
  155. 'provider' => 'admin_toolbar_tools',
  156. 'route_name' => 'entity.entity_view_display.' . $content_entity . '.default',
  157. 'menu_name' => 'admin',
  158. 'parent' => $content_entity_bundle_root,
  159. 'route_parameters' => [$content_entity_bundle => $machine_name],
  160. 'weight' => 3,
  161. ];
  162. }
  163. }
  164. if ($moduleHandler->moduleExists('devel') && $routeExists('entity.' . $content_entity_bundle . '.devel_load')) {
  165. $links['entity.' . $content_entity_bundle . '.devel_load.' . $machine_name] = [
  166. 'title' => t('Devel'),
  167. 'provider' => 'admin_toolbar_tools',
  168. 'route_name' => 'entity.' . $content_entity_bundle . '.devel_load',
  169. 'menu_name' => 'admin',
  170. 'parent' => $content_entity_bundle_root,
  171. 'route_parameters' => [$content_entity_bundle => $machine_name],
  172. 'weight' => 4,
  173. ];
  174. }
  175. if ($routeExists('entity.' . $content_entity_bundle . '.delete_form')) {
  176. $links['entity.' . $content_entity_bundle . '.delete_form.' . $machine_name] = [
  177. 'title' => t('Delete'),
  178. 'provider' => 'admin_toolbar_tools',
  179. 'route_name' => 'entity.' . $content_entity_bundle . '.delete_form',
  180. 'menu_name' => 'admin',
  181. 'parent' => $content_entity_bundle_root,
  182. 'route_parameters' => [$content_entity_bundle => $machine_name],
  183. 'weight' => 5,
  184. ];
  185. }
  186. }
  187. }
  188. // Add user links.
  189. $links['user.admin_create'] = [
  190. 'title' => t('Add a new user'),
  191. 'provider' => 'admin_toolbar_tools',
  192. 'route_name' => 'user.admin_create',
  193. 'menu_name' => 'admin',
  194. 'parent' => 'entity.user.collection',
  195. ];
  196. $links['user.admin_permissions'] = [
  197. 'title' => t('Permissions'),
  198. 'provider' => 'admin_toolbar_tools',
  199. 'route_name' => 'user.admin_permissions',
  200. 'menu_name' => 'admin',
  201. 'parent' => 'entity.user.collection',
  202. ];
  203. $links['entity.user_role.collection'] = [
  204. 'title' => t('Roles'),
  205. 'provider' => 'admin_toolbar_tools',
  206. 'route_name' => 'entity.user_role.collection',
  207. 'menu_name' => 'admin',
  208. 'parent' => 'entity.user.collection',
  209. ];
  210. $links['admin_toolbar_tools.user.logout'] = [
  211. 'title' => t('Logout'),
  212. 'provider' => 'admin_toolbar_tools',
  213. 'route_name' => 'user.logout',
  214. 'parent' => 'admin_toolbar_tools.help',
  215. 'weight' => 10,
  216. ];
  217. $links['user.role_add'] = [
  218. 'title' => t('Add a new role'),
  219. 'provider' => 'admin_toolbar_tools',
  220. 'route_name' => 'user.role_add',
  221. 'menu_name' => 'admin',
  222. 'parent' => 'entity.user_role.collection',
  223. 'weight' => -5,
  224. ];
  225. if ($moduleHandler->moduleExists('field_ui')) {
  226. $links['entity.user.field_ui_fields_'] = [
  227. 'title' => t('Manage fields'),
  228. 'provider' => 'admin_toolbar_tools',
  229. 'route_name' => 'entity.user.field_ui_fields',
  230. 'menu_name' => 'admin',
  231. 'parent' => 'entity.user.admin_form',
  232. ];
  233. $links['entity.entity_form_display.user.default_'] = [
  234. 'title' => t('Manage form display'),
  235. 'provider' => 'admin_toolbar_tools',
  236. 'route_name' => 'entity.entity_form_display.user.default',
  237. 'menu_name' => 'admin',
  238. 'parent' => 'entity.user.admin_form',
  239. ];
  240. $links['entity.entity_view_display.user.default_'] = [
  241. 'title' => t('Manage display'),
  242. 'provider' => 'admin_toolbar_tools',
  243. 'route_name' => 'entity.entity_view_display.user.default',
  244. 'menu_name' => 'admin',
  245. 'parent' => 'entity.user.admin_form',
  246. ];
  247. }
  248. foreach (user_roles() as $role) {
  249. $links['entity.user_role.edit_form.' . $role->id()] = [
  250. 'title' => t($role->label()),
  251. 'provider' => 'admin_toolbar_tools',
  252. 'route_name' => 'entity.user_role.edit_form',
  253. 'menu_name' => 'admin',
  254. 'parent' => 'entity.user_role.collection',
  255. 'route_parameters' => ['user_role' => $role->id()],
  256. ];
  257. $links['entity.user_role.edit_permissions_form.' . $role->id()] = [
  258. 'title' => t('Edit permissions'),
  259. 'provider' => 'admin_toolbar_tools',
  260. 'route_name' => 'entity.user_role.edit_permissions_form',
  261. 'menu_name' => 'admin',
  262. 'parent' => 'entity.user_role.edit_form.' . $role->id(),
  263. 'route_parameters' => ['user_role' => $role->id()],
  264. ];
  265. $links['entity.user_role.delete_form.' . $role->id()] = [
  266. 'title' => t('Delete'),
  267. 'provider' => 'admin_toolbar_tools',
  268. 'route_name' => 'entity.user_role.delete_form',
  269. 'menu_name' => 'admin',
  270. 'parent' => 'entity.user_role.edit_form.' . $role->id(),
  271. 'route_parameters' => ['user_role' => $role->id()],
  272. ];
  273. if ($moduleHandler->moduleExists('devel')) {
  274. $links['entity.user_role.devel_load.' . $role->id()] = [
  275. 'title' => t('Devel'),
  276. 'provider' => 'admin_toolbar_tools',
  277. 'route_name' => 'entity.user_role.devel_load',
  278. 'menu_name' => 'admin',
  279. 'parent' => 'entity.user_role.edit_form.' . $role->id(),
  280. 'route_parameters' => ['user_role' => $role->id()],
  281. ];
  282. }
  283. }
  284. if ($moduleHandler->moduleExists('node')) {
  285. $links['admin_toolbar_tools.add_content'] = $links['node.add_page'];
  286. $links['admin_toolbar_tools.add_content']['parent'] = 'system.admin_content';
  287. $links['node.type_add'] = [
  288. 'title' => t('Add content type'),
  289. 'provider' => 'admin_toolbar_tools',
  290. 'route_name' => 'node.type_add',
  291. 'menu_name' => 'admin',
  292. 'parent' => 'entity.node_type.collection',
  293. 'weight' => -5,
  294. ];
  295. // Add node links for each content type.
  296. foreach ($entityTypeManager->getStorage('node_type')->loadMultiple() as $type) {
  297. $links['node.add.' . $type->id()] = [
  298. 'title' => t($type->label()),
  299. 'provider' => 'admin_toolbar_tools',
  300. 'route_name' => 'node.add',
  301. 'parent' => 'admin_toolbar_tools.add_content',
  302. 'route_parameters' => ['node_type' => $type->id()],
  303. ];
  304. }
  305. }
  306. if ($moduleHandler->moduleExists('field_ui')) {
  307. $links['field_ui.entity_form_mode_add'] = [
  308. 'title' => t('Add new form mode'),
  309. 'provider' => 'admin_toolbar_tools',
  310. 'route_name' => 'field_ui.entity_form_mode_add',
  311. 'menu_name' => 'admin',
  312. 'parent' => 'entity.entity_form_mode.collection',
  313. ];
  314. $links['field_ui.entity_view_mode_add'] = [
  315. 'title' => t('Add new view mode'),
  316. 'provider' => 'admin_toolbar_tools',
  317. 'route_name' => 'field_ui.entity_view_mode_add',
  318. 'menu_name' => 'admin',
  319. 'parent' => 'entity.entity_view_mode.collection',
  320. ];
  321. }
  322. if ($moduleHandler->moduleExists('taxonomy')) {
  323. $links['entity.taxonomy_vocabulary.add_form'] = [
  324. 'title' => t('Add vocabulary'),
  325. 'provider' => 'admin_toolbar_tools',
  326. 'route_name' => 'entity.taxonomy_vocabulary.add_form',
  327. 'menu_name' => 'admin',
  328. 'parent' => 'entity.taxonomy_vocabulary.collection',
  329. 'weight' => -5,
  330. ];
  331. }
  332. if ($moduleHandler->moduleExists('menu_ui')) {
  333. $links['entity.menu.add_form'] = [
  334. 'title' => t('Add menu'),
  335. 'provider' => 'admin_toolbar_tools',
  336. 'route_name' => 'entity.menu.add_form',
  337. 'menu_name' => 'admin',
  338. 'parent' => 'entity.menu.collection',
  339. 'weight' => -50,
  340. ];
  341. // Adds links to /admin/structure/menu.
  342. foreach (menu_ui_get_menus() as $machine_name => $label) {
  343. $links['entity.menu.edit_form.' . $machine_name] = [
  344. 'title' => t($label),
  345. 'provider' => 'admin_toolbar_tools',
  346. 'route_name' => 'entity.menu.edit_form',
  347. 'menu_name' => 'admin',
  348. 'parent' => 'entity.menu.collection',
  349. 'route_parameters' => ['menu' => $machine_name],
  350. ];
  351. $links['entity.menu.delete_form.' . $machine_name] = [
  352. 'title' => t('Delete'),
  353. 'provider' => 'admin_toolbar_tools',
  354. 'route_name' => 'entity.menu.delete_form',
  355. 'menu_name' => 'admin',
  356. 'parent' => 'entity.menu.edit_form.' . $machine_name,
  357. 'route_parameters' => ['menu' => $machine_name],
  358. ];
  359. if ($moduleHandler->moduleExists('devel') && $routeExists('entity.menu.devel_load')) {
  360. $links['entity.menu.devel_load.' . $machine_name] = [
  361. 'title' => t('Devel'),
  362. 'provider' => 'admin_toolbar_tools',
  363. 'route_name' => 'entity.menu.devel_load',
  364. 'menu_name' => 'admin',
  365. 'parent' => 'entity.menu.edit_form.' . $machine_name,
  366. 'route_parameters' => ['menu' => $machine_name],
  367. ];
  368. }
  369. $links['entity.menu.add_link_form.' . $machine_name] = [
  370. 'title' => t('Add link'),
  371. 'provider' => 'admin_toolbar_tools',
  372. 'route_name' => 'entity.menu.add_link_form',
  373. 'menu_name' => 'admin',
  374. 'parent' => 'entity.menu.edit_form.' . $machine_name,
  375. 'route_parameters' => ['menu' => $machine_name],
  376. ];
  377. }
  378. }
  379. // If module block_content is enabled.
  380. if ($moduleHandler->moduleExists('block_content')) {
  381. $links['block_content.add_page'] = [
  382. 'title' => t('Add custom block'),
  383. 'provider' => 'admin_toolbar_tools',
  384. 'route_name' => 'block_content.add_page',
  385. 'menu_name' => 'admin',
  386. 'parent' => 'block.admin_display',
  387. 'weight' => -100,
  388. ];
  389. $links['entity.block_content.collection'] = [
  390. 'title' => t('Custom block library'),
  391. 'provider' => 'admin_toolbar_tools',
  392. 'route_name' => 'entity.block_content.collection',
  393. 'menu_name' => 'admin',
  394. 'parent' => 'block.admin_display',
  395. ];
  396. $links['entity.block_content_type.collection'] = [
  397. 'title' => t('Types'),
  398. 'provider' => 'admin_toolbar_tools',
  399. 'route_name' => 'entity.block_content_type.collection',
  400. 'menu_name' => 'admin',
  401. 'parent' => 'block.admin_display',
  402. ];
  403. }
  404. // If module Contact is enabled.
  405. if ($moduleHandler->moduleExists('contact')) {
  406. $links['contact.form_add'] = [
  407. 'title' => t('Add contact form'),
  408. 'provider' => 'admin_toolbar_tools',
  409. 'route_name' => 'contact.form_add',
  410. 'menu_name' => 'admin',
  411. 'parent' => 'entity.contact_form.collection',
  412. 'weight' => -5,
  413. ];
  414. }
  415. // If module Update Manager is enabled.
  416. if ($moduleHandler->moduleExists('update')) {
  417. $links['update.module_update'] = [
  418. 'title' => t('Update'),
  419. 'provider' => 'admin_toolbar_tools',
  420. 'route_name' => 'update.module_update',
  421. 'menu_name' => 'admin',
  422. 'parent' => 'system.modules_list',
  423. ];
  424. $links['update.module_install'] = [
  425. 'title' => t('Install new module'),
  426. 'provider' => 'admin_toolbar_tools',
  427. 'route_name' => 'update.module_install',
  428. 'menu_name' => 'admin',
  429. 'parent' => 'system.modules_list',
  430. ];
  431. }
  432. // If module Devel is enabled.
  433. if ($moduleHandler->moduleExists('devel')) {
  434. $links['admin_development'] = [
  435. 'title' => t('Development'),
  436. 'provider' => 'admin_toolbar_tools',
  437. 'route_name' => 'system.admin_config_development',
  438. 'menu_name' => 'admin',
  439. 'parent' => 'admin_toolbar_tools.help',
  440. 'weight' => '-8',
  441. ];
  442. $links['admin_toolbar_tools.devel.admin_settings'] = [
  443. 'title' => t('Devel settings'),
  444. 'provider' => 'admin_toolbar_tools',
  445. 'route_name' => 'devel.admin_settings',
  446. 'menu_name' => 'admin',
  447. 'parent' => 'admin_development',
  448. 'weight' => '-1',
  449. ];
  450. if ($moduleHandler->moduleExists('webprofiler')) {
  451. $links['admin_toolbar_tools.devel.webprofiler'] = [
  452. 'title' => t('Web Profiler settings'),
  453. 'provider' => 'admin_toolbar_tools',
  454. 'route_name' => 'webprofiler.settings',
  455. 'menu_name' => 'admin',
  456. 'parent' => 'admin_development',
  457. ];
  458. }
  459. $links['admin_toolbar_tools.devel.configs_list'] = [
  460. 'title' => t('Config editor'),
  461. 'provider' => 'admin_toolbar_tools',
  462. 'route_name' => 'devel.configs_list',
  463. 'menu_name' => 'admin',
  464. 'parent' => 'admin_development',
  465. ];
  466. $links['admin_toolbar_tools.devel.reinstall'] = [
  467. 'title' => t('Reinstall modules'),
  468. 'provider' => 'admin_toolbar_tools',
  469. 'route_name' => 'devel.reinstall',
  470. 'parent' => 'admin_development',
  471. ];
  472. $links['admin_toolbar_tools.devel.menu_rebuild'] = [
  473. 'title' => t('Rebuild menu'),
  474. 'provider' => 'admin_toolbar_tools',
  475. 'route_name' => 'devel.menu_rebuild',
  476. 'menu_name' => 'admin',
  477. 'parent' => 'admin_development',
  478. ];
  479. $links['admin_toolbar_tools.devel.state_system_page'] = [
  480. 'title' => t('State editor'),
  481. 'provider' => 'admin_toolbar_tools',
  482. 'route_name' => 'devel.state_system_page',
  483. 'menu_name' => 'admin',
  484. 'parent' => 'admin_development',
  485. ];
  486. $links['admin_toolbar_tools.devel.theme_registry'] = [
  487. 'title' => t('Theme registry'),
  488. 'provider' => 'admin_toolbar_tools',
  489. 'route_name' => 'devel.theme_registry',
  490. 'menu_name' => 'admin',
  491. 'parent' => 'admin_development',
  492. ];
  493. $links['admin_toolbar_tools.devel.entity_info_page'] = [
  494. 'title' => t('Entity Info'),
  495. 'provider' => 'admin_toolbar_tools',
  496. 'route_name' => 'devel.entity_info_page',
  497. 'menu_name' => 'admin',
  498. 'parent' => 'admin_development',
  499. ];
  500. $links['admin_toolbar_tools.devel.session'] = [
  501. 'title' => t('Session viewer'),
  502. 'provider' => 'admin_toolbar_tools',
  503. 'route_name' => 'devel.session',
  504. 'menu_name' => 'admin',
  505. 'parent' => 'admin_development',
  506. ];
  507. $links['admin_toolbar_tools.devel.elements_page'] = [
  508. 'title' => t('Form API field types'),
  509. 'provider' => 'admin_toolbar_tools',
  510. 'route_name' => 'devel.elements_page',
  511. 'menu_name' => 'admin',
  512. 'parent' => 'admin_development',
  513. ];
  514. // Menu link for the Toolbar module.
  515. $links['admin_toolbar_tools.toolbar.settings'] = [
  516. 'title' => t('Toolbar settings'),
  517. 'provider' => 'admin_toolbar_tools',
  518. 'route_name' => 'devel.toolbar.settings_form',
  519. 'menu_name' => 'admin',
  520. 'parent' => 'devel.admin_settings',
  521. ];
  522. }
  523. // If module Devel PHP is enabled.
  524. if ($moduleHandler->moduleExists('devel_php') && $routeExists('devel_php.execute_php')) {
  525. $links['admin_toolbar_tools.devel_php.execute_php'] = [
  526. 'title' => t('Execute PHP Code'),
  527. 'route_name' => 'devel_php.execute_php',
  528. 'menu_name' => 'admin',
  529. 'parent' => 'admin_development',
  530. ];
  531. }
  532. elseif ($moduleHandler->moduleExists('devel') && $routeExists('devel.execute_php')) {
  533. $links['admin_toolbar_tools.devel.execute_php'] = [
  534. 'title' => t('Execute PHP Code'),
  535. 'provider' => 'admin_toolbar_tools',
  536. 'route_name' => 'devel.execute_php',
  537. 'menu_name' => 'admin',
  538. 'parent' => 'admin_development',
  539. ];
  540. }
  541. // If module Views Ui enabled.
  542. if ($moduleHandler->moduleExists('views_ui')) {
  543. $links['admin_toolbar_tools.views_ui.add'] = [
  544. 'title' => t('Add new view'),
  545. 'provider' => 'admin_toolbar_tools',
  546. 'route_name' => 'views_ui.add',
  547. 'menu_name' => 'admin',
  548. 'parent' => 'entity.view.collection',
  549. 'weight' => -5,
  550. ];
  551. $links['admin_toolbar_tools.views_ui.field_list'] = [
  552. 'title' => t('Used in views'),
  553. 'provider' => 'admin_toolbar_tools',
  554. 'route_name' => 'views_ui.reports_fields',
  555. 'menu_name' => 'admin',
  556. 'parent' => 'entity.field_storage_config.collection',
  557. ];
  558. }
  559. $links['admin_toolbar_tools.system.theme_settings'] = [
  560. 'title' => t('Settings'),
  561. 'provider' => 'admin_toolbar_tools',
  562. 'route_name' => 'system.theme_settings',
  563. 'menu_name' => 'admin',
  564. 'parent' => 'system.themes_page',
  565. ];
  566. if ($moduleHandler->moduleExists('webprofiler')) {
  567. $links['admin_toolbar_tools.devel.webprofiler'] = [
  568. 'title' => t('Webprofiler settings'),
  569. 'provider' => 'admin_toolbar_tools',
  570. 'route_name' => 'webprofiler.settings',
  571. 'menu_name' => 'admin',
  572. 'parent' => 'admin_development',
  573. ];
  574. }
  575. if ($moduleHandler->moduleExists('update')) {
  576. $links['update.theme_install_'] = [
  577. 'title' => t('Install new theme'),
  578. 'provider' => 'admin_toolbar_tools',
  579. 'route_name' => 'update.theme_install',
  580. 'menu_name' => 'admin',
  581. 'parent' => 'system.themes_page',
  582. ];
  583. $links['update.theme_update_'] = [
  584. 'title' => t('Update'),
  585. 'provider' => 'admin_toolbar_tools',
  586. 'route_name' => 'update.theme_update',
  587. 'menu_name' => 'admin',
  588. 'parent' => 'system.themes_page',
  589. ];
  590. // Lists installed themes.
  591. $installed_themes = admin_toolbar_tools_installed_themes();
  592. foreach ($installed_themes as $key_theme => $label_theme) {
  593. $links['system.theme_settings_theme.' . $key_theme] = [
  594. 'title' => t($label_theme),
  595. 'provider' => 'admin_toolbar_tools',
  596. 'route_name' => 'system.theme_settings_theme',
  597. 'menu_name' => 'admin',
  598. 'parent' => 'system.theme_settings_',
  599. 'route_parameters' => [
  600. 'theme' => $key_theme,
  601. ],
  602. ];
  603. }
  604. }
  605. // If module Language enabled.
  606. if ($moduleHandler->moduleExists('language')) {
  607. $links['admin_toolbar_tools.language.negotiation'] = [
  608. 'title' => t('Detection and selection'),
  609. 'provider' => 'admin_toolbar_tools',
  610. 'route_name' => 'language.negotiation',
  611. 'menu_name' => 'admin',
  612. 'parent' => 'entity.configurable_language.collection',
  613. ];
  614. }
  615. // If module Media enabled.
  616. if ($moduleHandler->moduleExists('media')) {
  617. $links['admin_toolbar_tools.add_media'] = [
  618. 'title' => t('Add media'),
  619. 'provider' => 'admin_toolbar_tools',
  620. 'route_name' => 'entity.media.add_page',
  621. 'menu_name' => 'admin',
  622. 'parent' => 'system.admin_content',
  623. ];
  624. // Add node links for each media type.
  625. foreach ($entityTypeManager->getStorage('media_type')->loadMultiple() as $type) {
  626. $links['media.add.' . $type->id()] = [
  627. 'title' => t($type->label()),
  628. 'provider' => 'admin_toolbar_tools',
  629. 'route_name' => 'entity.media.add_form',
  630. 'parent' => 'admin_toolbar_tools.add_media',
  631. 'route_parameters' => ['media_type' => $type->id()],
  632. ];
  633. }
  634. }
  635. // If module Config enabled.
  636. if ($moduleHandler->moduleExists('config')) {
  637. $links['admin_toolbar_tools.config.import'] = [
  638. 'title' => t('Import'),
  639. 'provider' => 'admin_toolbar_tools',
  640. 'route_name' => 'config.import_full',
  641. 'menu_name' => 'admin',
  642. 'parent' => 'config.sync',
  643. 'weight' => 1,
  644. ];
  645. $links['admin_toolbar_tools.config.export'] = [
  646. 'title' => t('Export'),
  647. 'provider' => 'admin_toolbar_tools',
  648. 'route_name' => 'config.export_full',
  649. 'menu_name' => 'admin',
  650. 'parent' => 'config.sync',
  651. 'weight' => 2,
  652. ];
  653. }
  654. $languageManager->setConfigOverrideLanguage($config_override_language);
  655. }
  656. /**
  657. * Return installed themes.
  658. *
  659. * @return array
  660. * An array of friendly theme names, keyed by the machine name.
  661. */
  662. function admin_toolbar_tools_installed_themes() {
  663. $themeHandler = \Drupal::service('theme_handler');
  664. $all_themes = $themeHandler->listInfo();
  665. $themes_installed = [];
  666. foreach ($all_themes as $key_theme => $theme) {
  667. if ($themeHandler->hasUi($key_theme)) {
  668. $themes_installed[$key_theme] = $themeHandler->getName($key_theme);
  669. }
  670. }
  671. return $themes_installed;
  672. }