You are here

function admin_menu_admin_menu_output_build in Administration menu 8.3

Same name and namespace in other branches
  1. 6.3 admin_menu.module \admin_menu_admin_menu_output_build()
  2. 7.3 admin_menu.module \admin_menu_admin_menu_output_build()

Implements hook_admin_menu_output_build().

File

./admin_menu.module, line 559
Render an administrative menu as a dropdown menu at the top of the window.

Code

function admin_menu_admin_menu_output_build(&$content) {
  if (!isset($content['menu'])) {
    return;
  }

  // Unassign weights for categories below Configuration.
  // An alphabetical order is more natural for a dropdown menu.
  if (isset($content['menu']['admin/config'])) {
    foreach (element_children($content['menu']['admin/config']) as $key) {
      $content['menu']['admin/config'][$key]['#weight_original'] = $content['menu']['admin/config'][$key]['#weight'];
      unset($content['menu']['admin/config'][$key]['#weight']);
    }
  }

  // Retrieve the "Add content" link tree.
  // TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
  // You will need to use `\Drupal\core\Database\Database::getConnection()` if you do not yet have access to the container here.
  $link = \Drupal::database()
    ->query("SELECT * FROM {menu_links} WHERE router_path = 'node/add' AND module = 'system'")
    ->fetchAssoc();
  $conditions = [];
  for ($i = 1; $i < MENU_MAX_DEPTH; $i++) {
    if (!empty($link["p{$i}"])) {
      $conditions["p{$i}"] = $link["p{$i}"];
    }
  }
  $tree = menu_build_tree($link['menu_name'], [
    'conditions' => $conditions,
    'min_depth' => $link['depth'],
  ]);
  $links = admin_menu_links_menu($tree);
  if (!empty($links)) {

    // If the user has access to the top-level "Content" category, insert the
    // "Add content" link tree there.
    if (isset($content['menu']['admin/content'])) {
      $content['menu']['admin/content'] += $links;
    }
    else {
      $key = key($links);
      $links[$key]['#weight'] = -100;
      $content['menu'] += $links;
    }
  }
}