summaryrefslogtreecommitdiff
path: root/modules/menu/menu.install
blob: 717c5e7126b8141c432dd6603531b914f089ed81 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php

/**
 * @file
 * Install, update and uninstall functions for the menu module.
 */

/**
 * Implements hook_schema().
 */
function menu_schema() {
  $schema['menu_custom'] = array(
    'description' => 'Holds definitions for top-level custom menus (for example, Main menu).',
    'fields' => array(
      'menu_name' => array(
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Primary Key: Unique key for menu. This is used as a block delta so length is 32.',
      ),
      'title' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Menu title; displayed at top of block.',
        'translatable' => TRUE,
      ),
      'description' => array(
        'type' => 'text',
        'not null' => FALSE,
        'description' => 'Menu description.',
        'translatable' => TRUE,
      ),
    ),
    'primary key' => array('menu_name'),
  );

  return $schema;
}

/**
 * Implements hook_install().
 */
function menu_install() {
  $system_menus = menu_list_system_menus();
  $t = get_t();
  $descriptions = array(
    'navigation' => $t('The <em>Navigation</em> menu contains links intended for site visitors. Links are added to the <em>Navigation</em> menu automatically by some modules.'),
    'user-menu' => $t("The <em>User</em> menu contains links related to the user's account, as well as the 'Log out' link."),
    'management' => $t('The <em>Management</em> menu contains links for administrative tasks.'),
    'main-menu' => $t('The <em>Main</em> menu is used on many sites to show the major sections of the site, often in a top navigation bar.'),
  );
  foreach ($system_menus as $menu_name => $title) {
    $menu = array(
      'menu_name' => $menu_name,
      'title' => $t($title),
      'description' => $descriptions[$menu_name],
    );
    menu_save($menu);
  }
}

/**
 * Implements hook_uninstall().
 */
function menu_uninstall() {
  menu_rebuild();
}

/**
 * @defgroup updates-7.x-extra Extra updates for 7.x
 * @{
 */

/**
 * Migrate the "Default menu for content" setting to individual node types.
 */
function menu_update_7000() {
  // Act only on sites originally on Drupal 6 that have a custom "Default menu
  // for content" setting.
  $default_node_menu = variable_get('menu_default_node_menu');
  if (isset($default_node_menu)) {
    // Remove variable no longer used in Drupal 7.
    variable_del('menu_default_node_menu');

    // Make sure the menu chosen as the default still exists.
    $defined_menus = db_query('SELECT * FROM {menu_custom}')->fetchAllAssoc('menu_name', PDO::FETCH_ASSOC);
    // If the menu does not exist, do nothing; nodes will use the default D7
    // node menu settings.
    if (!isset($defined_menus[$default_node_menu])) {
      return;
    }

    // Update the menu settings for each node type.
    foreach (_update_7000_node_get_types() as $type => $type_object) {
      $type_menus = variable_get('menu_options_' . $type);
      // If the site already has a custom menu setting for this node type (set
      // on the initial upgrade to Drupal 7.0), don't override it.
      if (!isset($type_menus)) {
        // Set up this node type so that the Drupal 6 "Default menu for content"
        // is still available in the "Menu settings" section.
        variable_set('menu_options_' . $type, array($default_node_menu));
        variable_set('menu_parent_' . $type, $default_node_menu . ':0');
      }
    }
  }
}

/**
 * @} End of "defgroup updates-7.x-extra"
 * The next series of updates should start at 8000.
 */