1 admin_bar.module admin_bar_admin_bar_output_build(&$content)

Implements hook_admin_bar_output_build().

File

core/modules/admin_bar/admin_bar.module, line 560
Render an administrative bar as a dropdown menu at the top of the window.

Code

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

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

  // Move node/add under the "Content" item if it already exists in the menu.
  if (isset($content['menu']['menu']['node/add']) && isset($content['menu']['menu']['admin/content'])) {
    $content['menu']['menu']['admin/content']['node/add'] = $content['menu']['menu']['node/add'];
    unset($content['menu']['menu']['node/add']);
  }
  // Retrieve and insert node/add if it does not yet exist in the menu.
  else {
    $link = db_query("SELECT * FROM {menu_links} WHERE router_path = 'node/add' AND module = 'system'")->fetchAssoc();
    $conditions = array();
    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'], array(
      'conditions' => $conditions,
      'min_depth' => $link['depth'],
    ));
    $links = admin_bar_links_menu($tree);
    if (!empty($links)) {
      $key = key($links);
      $links[$key]['#weight'] = -100;

      // If the user has access to the top-level "Content" category, insert the
      // "Add content" link tree there.
      if (isset($content['menu']['menu']['admin/content'])) {
        $content['menu']['menu']['admin/content'] += $links;
      }
      // Otherwise make insert "Add content" as top-level category.
      else {
        $content['menu']['menu'] += $links;
      }
    }
  }
  // Move file/add under the "Content" item.
  if (isset($content['menu']['menu']['file/add']) && isset($content['menu']['menu']['admin/content'])) {
    $content['menu']['menu']['admin/content']['file/add'] = $content['menu']['menu']['file/add'];
    unset($content['menu']['menu']['file/add']);
  }
}