summaryrefslogtreecommitdiff
path: root/modules/toolbar/toolbar.install
blob: 3dcc4f5e7d314c71f9359d0780992092a02e9527 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
// $Id$

/**
 * @file
 * Installation functions for admin toolbar.
 */

/**
 * Implementation of hook_install().
 *
 * @todo
 *   Implement role based shortcut bars.
 */
function toolbar_install() {
  $t = get_t();
  $menu = array(
    'menu_name' => 'admin_shortcuts',
    'title' => $t('Administration shortcuts'),
    'description' => $t('The <em>Administration shortcuts</em> menu contains commonly used links for administrative tasks.'),
  );
  menu_save($menu);

  // Add starter convenience shortcuts.
  menu_rebuild();
  $items = array(
    'node/add' => 'Add content',
    'admin/content' => 'Find content',
    'admin/dashboard' => 'Dashboard',
  );
  $weight = -20;
  foreach ($items as $path => $title) {
    $link = array(
      'mlid' => 0,
      'link_title' => $title,
      'link_path' => $path,
      'router_path' => $path,
      'menu_name' => 'admin_shortcuts',
      'module' => 'menu',
      'weight' => $weight,
    );

    // Check for an existing menu item before attempting to create a new one.
    $menu_link = db_query("SELECT mlid FROM {menu_links} WHERE link_path = :path AND menu_name = :menu_name", array(
      ':path' => $link['link_path'],
      ':menu_name' => $link['menu_name']
    ))
    ->fetchField();
    if (!$menu_link) {
      menu_link_save($link);
    }

    // Increment weight so items can be displayed in desired order.
    $weight++;
  }
}