Mercurial > hg > rr-repo
comparison modules/menu/menu.install @ 0:ff03f76ab3fe
initial version
author | danieleb <danielebarchiesi@me.com> |
---|---|
date | Wed, 21 Aug 2013 18:51:11 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ff03f76ab3fe |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * @file | |
5 * Install, update and uninstall functions for the menu module. | |
6 */ | |
7 | |
8 /** | |
9 * Implements hook_schema(). | |
10 */ | |
11 function menu_schema() { | |
12 $schema['menu_custom'] = array( | |
13 'description' => 'Holds definitions for top-level custom menus (for example, Main menu).', | |
14 'fields' => array( | |
15 'menu_name' => array( | |
16 'type' => 'varchar', | |
17 'length' => 32, | |
18 'not null' => TRUE, | |
19 'default' => '', | |
20 'description' => 'Primary Key: Unique key for menu. This is used as a block delta so length is 32.', | |
21 ), | |
22 'title' => array( | |
23 'type' => 'varchar', | |
24 'length' => 255, | |
25 'not null' => TRUE, | |
26 'default' => '', | |
27 'description' => 'Menu title; displayed at top of block.', | |
28 'translatable' => TRUE, | |
29 ), | |
30 'description' => array( | |
31 'type' => 'text', | |
32 'not null' => FALSE, | |
33 'description' => 'Menu description.', | |
34 'translatable' => TRUE, | |
35 ), | |
36 ), | |
37 'primary key' => array('menu_name'), | |
38 ); | |
39 | |
40 return $schema; | |
41 } | |
42 | |
43 /** | |
44 * Implements hook_install(). | |
45 */ | |
46 function menu_install() { | |
47 $system_menus = menu_list_system_menus(); | |
48 $t = get_t(); | |
49 $descriptions = array( | |
50 '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.'), | |
51 'user-menu' => $t("The <em>User</em> menu contains links related to the user's account, as well as the 'Log out' link."), | |
52 'management' => $t('The <em>Management</em> menu contains links for administrative tasks.'), | |
53 '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.'), | |
54 ); | |
55 foreach ($system_menus as $menu_name => $title) { | |
56 $menu = array( | |
57 'menu_name' => $menu_name, | |
58 'title' => $t($title), | |
59 'description' => $descriptions[$menu_name], | |
60 ); | |
61 menu_save($menu); | |
62 } | |
63 } | |
64 | |
65 /** | |
66 * Implements hook_uninstall(). | |
67 */ | |
68 function menu_uninstall() { | |
69 menu_rebuild(); | |
70 } | |
71 | |
72 /** | |
73 * @addtogroup updates-7.x-extra | |
74 * @{ | |
75 */ | |
76 | |
77 /** | |
78 * Migrate the "Default menu for content" setting to individual node types. | |
79 */ | |
80 function menu_update_7000() { | |
81 // Act only on sites originally on Drupal 6 that have a custom "Default menu | |
82 // for content" setting. | |
83 $default_node_menu = variable_get('menu_default_node_menu'); | |
84 if (isset($default_node_menu)) { | |
85 // Remove variable no longer used in Drupal 7. | |
86 variable_del('menu_default_node_menu'); | |
87 | |
88 // Make sure the menu chosen as the default still exists. | |
89 $defined_menus = db_query('SELECT * FROM {menu_custom}')->fetchAllAssoc('menu_name', PDO::FETCH_ASSOC); | |
90 // If the menu does not exist, do nothing; nodes will use the default D7 | |
91 // node menu settings. | |
92 if (!isset($defined_menus[$default_node_menu])) { | |
93 return; | |
94 } | |
95 | |
96 // Update the menu settings for each node type. | |
97 foreach (_update_7000_node_get_types() as $type => $type_object) { | |
98 $type_menus = variable_get('menu_options_' . $type); | |
99 // If the site already has a custom menu setting for this node type (set | |
100 // on the initial upgrade to Drupal 7.0), don't override it. | |
101 if (!isset($type_menus)) { | |
102 // Set up this node type so that the Drupal 6 "Default menu for content" | |
103 // is still available in the "Menu settings" section. | |
104 variable_set('menu_options_' . $type, array($default_node_menu)); | |
105 variable_set('menu_parent_' . $type, $default_node_menu . ':0'); | |
106 } | |
107 } | |
108 } | |
109 } | |
110 | |
111 /** | |
112 * Rename "Primary Links" and "Secondary Links" to their Drupal 7 equivalents. | |
113 */ | |
114 function menu_update_7001() { | |
115 // Migrate D6 menu_primary_links_source to D7 menu_main_links_source (without | |
116 // renaming). | |
117 if (variable_get('menu_primary_links_source') !== NULL) { | |
118 variable_set('menu_main_links_source', variable_get('menu_primary_links_source')); | |
119 variable_del('menu_primary_links_source'); | |
120 } | |
121 | |
122 // Rename each menu, and any settings that refer to the old menu name. | |
123 // - "Primary Links" has become system menu "Main menu". | |
124 // - "Secondary Links" has become a new custom menu "Secondary menu". | |
125 $rename = array( | |
126 'primary-links' => array('main-menu', 'Main menu'), | |
127 'secondary-links' => array('secondary-menu', 'Secondary menu'), | |
128 ); | |
129 foreach ($rename as $from_menu => $to) { | |
130 list($to_menu, $to_title) = $to; | |
131 // Rename the menu, and links in the menu. | |
132 db_update('menu_custom') | |
133 ->fields(array('menu_name' => $to_menu, 'title' => $to_title)) | |
134 ->condition('menu_name', $from_menu) | |
135 ->execute(); | |
136 db_update('menu_links') | |
137 ->fields(array('menu_name' => $to_menu)) | |
138 ->condition('menu_name', $from_menu) | |
139 ->execute(); | |
140 | |
141 // Update any content type that used this menu as a default menu. | |
142 // Note: these variables may be unset/default, in which case we leave them | |
143 // alone. See menu_update_7000() | |
144 foreach (_update_7000_node_get_types() as $type => $type_object) { | |
145 $menu_options = variable_get('menu_options_' . $type); | |
146 if ($menu_options !== NULL) { | |
147 variable_set('menu_options_' . $type, str_replace($from_menu, $to_menu, $menu_options)); | |
148 if (variable_get('menu_parent_' . $type) == $from_menu . ':0') { | |
149 variable_set('menu_parent_' . $type, $to_menu . ':0'); | |
150 } | |
151 } | |
152 } | |
153 | |
154 // Update the "source for primary links" and "source for secondary links" to | |
155 // follow. | |
156 if (variable_get('menu_main_links_source') == $from_menu) { | |
157 variable_set('menu_main_links_source', $to_menu); | |
158 } | |
159 if (variable_get('menu_secondary_links_source') == $from_menu) { | |
160 variable_set('menu_secondary_links_source', $to_menu); | |
161 } | |
162 } | |
163 } | |
164 | |
165 /** | |
166 * Rename the primary/secondary menu blocks to match previously renamed menus. | |
167 */ | |
168 function menu_update_7002(&$sandbox) { | |
169 // Check for the presence of old or new table names. | |
170 if (db_table_exists('blocks') || db_table_exists('block')) { | |
171 $renamed_deltas = array( | |
172 'menu' => array( | |
173 'primary-links' => 'main-menu', | |
174 'secondary-links' => 'secondary-menu', | |
175 ), | |
176 ); | |
177 | |
178 $moved_deltas = array( | |
179 'menu' => array('main-menu' => 'system'), | |
180 ); | |
181 | |
182 update_fix_d7_block_deltas($sandbox, $renamed_deltas, $moved_deltas); | |
183 } | |
184 } | |
185 /** | |
186 * Add missing custom menus to active menus list. | |
187 */ | |
188 function menu_update_7003(&$sandbox) { | |
189 // Make sure all custom menus are present in the active menus variable so that | |
190 // their items may appear in the active trail. | |
191 // @see menu_set_active_menu_names() | |
192 $active_menus = variable_get('menu_default_active_menus', array_keys(menu_list_system_menus())); | |
193 $update_variable = FALSE; | |
194 foreach (menu_get_names() as $menu_name) { | |
195 if (!in_array($menu_name, $active_menus) && (strpos($menu_name, 'menu-') === 0)) { | |
196 $active_menus[] = $menu_name; | |
197 $update_variable = TRUE; | |
198 } | |
199 } | |
200 if ($update_variable) { | |
201 variable_set('menu_default_active_menus', $active_menus); | |
202 } | |
203 // Clear the menu cache. | |
204 cache_clear_all(NULL, 'cache_menu'); | |
205 } | |
206 | |
207 /** | |
208 * @} End of "addtogroup updates-7.x-extra". | |
209 * The next series of updates should start at 8000. | |
210 */ |