You are here

admin_toolbar_tools.module in Zircon Profile 8

Prvides extra menu links for admin_toolbar.

File

modules/admin_toolbar/admin_toolbar_tools/admin_toolbar_tools.module
View source
<?php

use Drupal\Core\Routing\RouteMatchInterface;

/**
 * @file
 * Prvides extra menu links for admin_toolbar.
 */

/**
 * Implements hook_toolbar().
 */
function admin_toolbar_tools_toolbar() {
  $items = array();
  $items['admin_toolbar_tools'] = array(
    '#type' => 'toolbar_item',
    '#attributes' => array(
      'class' => array(
        'toolbar-icon',
        'toolbar-icon-admin-toolbar-tools-help',
      ),
    ),
    '#attached' => array(
      'library' => array(
        'admin_toolbar_tools/toolbar.icon',
      ),
    ),
  );
  return $items;
}

/**
 *  Implements hook_help().
 */
function admin_toolbar_tools_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.admin_toolbar_tools':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('The Admin Toolbar Tools module allows you to to add more fonctionalities to the toolbar like flush caches, runnig cron.') . '</p>';
      return $output;
  }
}

/**
 *  Implements hook_menu_links_discovered_alter().
 */
function admin_toolbar_tools_menu_links_discovered_alter(&$links) {
  $links['admin_toolbar_tools.help'] = array(
    'title' => 'Tools',
    'route_name' => '<front>',
    'parent' => 'system.admin',
    'weight' => -100,
  );

  // Add system links.
  $links['system.admin_index'] = array(
    'title' => 'Index',
    'route_name' => 'system.admin_index',
    'parent' => 'admin_toolbar_tools.help',
    'weight' => -100,
  );
  $links['system.run_cron'] = array(
    'title' => 'Run cron',
    'route_name' => 'admin_toolbar.run.cron',
    'parent' => 'admin_toolbar_tools.help',
    'weight' => -8,
  );
  $links['system.db_update'] = array(
    'title' => 'Run Updates',
    'route_name' => 'system.db_update',
    'parent' => 'admin_toolbar_tools.help',
    'weight' => -6,
  );
  $links['system.modules_uninstall'] = array(
    'title' => 'Uninstall',
    'route_name' => 'system.modules_uninstall',
    'parent' => 'system.modules_list',
  );

  // Add user links.
  $links['user.admin_create'] = array(
    'title' => 'Add user',
    'route_name' => 'user.admin_create',
    'parent' => 'entity.user.collection',
  );
  $links['user.admin_permissions'] = array(
    'title' => 'Permissions',
    'route_name' => 'user.admin_permissions',
    'parent' => 'entity.user.collection',
  );
  $links['entity.user_role.collection'] = array(
    'title' => 'Roles',
    'route_name' => 'entity.user_role.collection',
    'parent' => 'entity.user.collection',
  );
  $links['user.logout'] = array(
    'title' => 'Logout',
    'route_name' => 'user.logout',
    'parent' => 'admin_toolbar_tools.help',
    'weight' => 10,
  );
  $links['user.role_add'] = array(
    'title' => 'Add role',
    'route_name' => 'user.role_add',
    'parent' => 'entity.user_role.collection',
    'weight' => -5,
  );
  foreach (user_roles() as $role) {
    $links['entity.user_role.edit_form.' . $role
      ->id()] = array(
      'title' => $role
        ->label(),
      'route_name' => 'entity.user_role.edit_form',
      'parent' => 'entity.user_role.collection',
      'route_parameters' => array(
        'user_role' => $role
          ->id(),
      ),
    );
  }
  $links['node.add_page']['parent'] = 'system.admin_content';
  $links['node.type_add'] = array(
    'title' => 'Add content type',
    'route_name' => 'node.type_add',
    'parent' => 'entity.node_type.collection',
    'weight' => -5,
  );

  // Add node links.
  foreach (node_type_get_names() as $machine_name => $label) {
    $links['node.add.' . $machine_name] = array(
      'title' => $label,
      'route_name' => 'node.add',
      'parent' => 'node.add_page',
      'route_parameters' => array(
        'node_type' => $machine_name,
      ),
    );
    $links['entity.node_type.edit_form.' . $machine_name] = array(
      'title' => $label,
      'route_name' => 'entity.node_type.edit_form',
      'parent' => 'entity.node_type.collection',
      'route_parameters' => array(
        'node_type' => $machine_name,
      ),
    );
    $links['entity.node_type.delete_form.' . $machine_name] = array(
      'title' => 'Delete',
      'route_name' => 'entity.node_type.delete_form',
      'parent' => 'entity.node_type.edit_form.' . $machine_name,
      'route_parameters' => array(
        'node_type' => $machine_name,
      ),
    );
  }

  // If module taxonomy is enabled.
  if (\Drupal::moduleHandler()
    ->moduleExists('taxonomy')) {
    $links['entity.taxonomy_vocabulary.add_form'] = array(
      'title' => 'Add vocabulary',
      'route_name' => 'entity.taxonomy_vocabulary.add_form',
      'parent' => 'entity.taxonomy_vocabulary.collection',
      'weight' => -5,
    );

    // Add taxonomy links.
    foreach (\Drupal::entityManager()
      ->getBundleInfo('taxonomy_term') as $machine_name => $bundle) {
      $links['entity.taxonomy_vocabulary.edit_form.' . $machine_name] = array(
        'title' => $bundle['label'],
        'route_name' => 'entity.taxonomy_vocabulary.edit_form',
        'parent' => 'entity.taxonomy_vocabulary.collection',
        'route_parameters' => array(
          'taxonomy_vocabulary' => $machine_name,
        ),
      );
      $links['entity.taxonomy_term.add_form.' . $machine_name] = array(
        'title' => $bundle['label'],
        'route_name' => 'entity.taxonomy_term.add_form',
        'parent' => 'entity.taxonomy_vocabulary.edit_form',
        'route_parameters' => array(
          'taxonomy_vocabulary' => $machine_name,
        ),
      );
    }
  }

  // If module comment is enabled.
  if (\Drupal::moduleHandler()
    ->moduleExists('comment')) {
    $links['entity.comment_type.add_form'] = array(
      'title' => 'Add comment type',
      'route_name' => 'entity.comment_type.add_form',
      'parent' => 'entity.comment_type.collection',
      'weight' => -5,
    );
    $links['comment.admin_approval'] = array(
      'title' => 'Unapproved comments',
      'route_name' => 'comment.admin_approval',
      'parent' => 'comment.admin',
      'weight' => -5,
    );

    // Add comments links.
    foreach (\Drupal::entityManager()
      ->getBundleInfo('comment') as $machine_name => $bundle) {
      $links['entity.comment_type.edit_form.' . $machine_name] = array(
        'title' => $bundle['label'],
        'route_name' => 'entity.comment_type.edit_form',
        'parent' => 'entity.comment_type.collection',
        'route_parameters' => array(
          'comment_type' => $machine_name,
        ),
      );
    }
  }

  // If module menu_ui is enabled.
  if (\Drupal::moduleHandler()
    ->moduleExists('menu_ui')) {
    $links['entity.menu.add_form'] = array(
      'title' => 'Add menu',
      'route_name' => 'entity.menu.add_form',
      'parent' => 'entity.menu.collection',
      'weight' => -50,
    );

    // Adding links to /admin/structure/menu.
    foreach (menu_ui_get_menus() as $machine_name => $label) {
      $links['entity.menu.edit_form.' . $machine_name] = array(
        'title' => $label,
        'route_name' => 'entity.menu.edit_form',
        'parent' => 'entity.menu.collection',
        'route_parameters' => array(
          'menu' => $machine_name,
        ),
      );
    }
  }

  // If module block_content is enabled.
  if (\Drupal::moduleHandler()
    ->moduleExists('block_content')) {
    $links['block_content.add_page'] = array(
      'title' => 'Add custom block',
      'route_name' => 'block_content.add_page',
      'parent' => 'block.admin_display',
      'weight' => -100,
    );
    $links['entity.block_content.collection'] = array(
      'title' => 'Custom block library',
      'route_name' => 'entity.block_content.collection',
      'parent' => 'block.admin_display',
    );
    $links['entity.block_content_type.collection'] = array(
      'title' => 'Types',
      'route_name' => 'entity.block_content_type.collection',
      'parent' => 'block.admin_display',
    );
    $links['block_content.type_add'] = array(
      'title' => 'Add custom block type',
      'route_name' => 'block_content.type_add',
      'parent' => 'entity.block_content_type.collection',
      'weight' => -100,
    );
  }

  // If module contact is enabled.
  if (\Drupal::moduleHandler()
    ->moduleExists('contact')) {
    $links['contact.form_add'] = array(
      'title' => 'Add contact form',
      'route_name' => 'contact.form_add',
      'parent' => 'entity.contact_form.collection',
      'weight' => -5,
    );

    // Add contact links.
    foreach (\Drupal::entityManager()
      ->getBundleInfo('contact_message') as $machine_name => $bundle) {
      $links['entity.contact_form.edit_form.' . $machine_name] = array(
        'title' => $bundle['label'],
        'route_name' => 'entity.contact_form.edit_form',
        'parent' => 'entity.contact_form.collection',
        'route_parameters' => array(
          'contact_form' => $machine_name,
        ),
      );
    }
  }

  // If module update is enabled.
  if (\Drupal::moduleHandler()
    ->moduleExists('update')) {
    $links['update.module_update'] = array(
      'title' => 'Update',
      'route_name' => 'update.module_update',
      'parent' => 'system.modules_list',
    );
    $links['update.module_install'] = array(
      'title' => 'Install new module',
      'route_name' => 'update.module_install',
      'parent' => 'system.modules_list',
    );
  }
  if (\Drupal::moduleHandler()
    ->moduleExists('devel')) {
    $links['admin_development'] = array(
      'title' => 'Development',
      'route_name' => 'system.admin_config_development',
      'parent' => 'admin_toolbar_tools.help',
      'weight' => -8,
    );
    $links['devel.admin_settings'] = array(
      'title' => 'Devel settings',
      'route_name' => 'devel.admin_settings',
      'parent' => 'admin_development',
    );
    $links['devel.configs_list'] = array(
      'title' => 'Config editor',
      'route_name' => 'devel.configs_list',
      'parent' => 'admin_development',
    );
    $links['devel.reinstall'] = array(
      'title' => 'Reinstall Modules',
      'route_name' => 'devel.reinstall',
      'parent' => 'admin_development',
    );
    $links['devel.menu_rebuild'] = array(
      'title' => 'Rebuild Menu',
      'route_name' => 'devel.menu_rebuild',
      'parent' => 'admin_development',
    );
    $links['devel.state_system_page'] = array(
      'title' => 'State editor',
      'route_name' => 'devel.state_system_page',
      'parent' => 'admin_development',
    );
    $links['devel.theme_registry'] = array(
      'title' => 'Theme registry',
      'route_name' => 'devel.theme_registry',
      'parent' => 'admin_development',
    );
    $links['devel.entity_info_page'] = array(
      'title' => 'Entity Info',
      'route_name' => 'devel.entity_info_page',
      'parent' => 'admin_development',
    );
    $links['devel.execute_php'] = array(
      'title' => 'Execute PHP',
      'route_name' => 'devel.execute_php',
      'parent' => 'admin_development',
    );
    $links['devel.session'] = array(
      'title' => 'View Session',
      'route_name' => 'devel.session',
      'parent' => 'admin_development',
    );
    $links['devel.elements_page'] = array(
      'title' => 'Hook_elements',
      'route_name' => 'devel.elements_page',
      'parent' => 'admin_development',
    );
  }
}