- Patch #216813 by pwolanin et al: fixed upgrade path for primary links and navigation.
parent
ca88c5f4c1
commit
a730d23d14
|
@ -1173,7 +1173,7 @@ function menu_list_system_menus() {
|
|||
* Return an array of links to be rendered as the Primary links.
|
||||
*/
|
||||
function menu_primary_links() {
|
||||
return menu_navigation_links('primary-links');
|
||||
return menu_navigation_links(variable_get('menu_primary_links_source', 'primary-links'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1183,11 +1183,11 @@ function menu_secondary_links() {
|
|||
|
||||
// If the secondary menu source is set as the primary menu, we display the
|
||||
// second level of the primary menu.
|
||||
if (variable_get('menu_secondary_links_source', 'secondary-links') == 'primary-links') {
|
||||
return menu_navigation_links('primary-links', 1);
|
||||
if (variable_get('menu_secondary_links_source', 'secondary-links') == variable_get('menu_primary_links_source', 'primary-links')) {
|
||||
return menu_navigation_links(variable_get('menu_primary_links_source', 'primary-links'), 1);
|
||||
}
|
||||
else {
|
||||
return menu_navigation_links('secondary-links', 0);
|
||||
return menu_navigation_links(variable_get('menu_secondary_links_source', 'secondary-links'), 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -604,21 +604,33 @@ function menu_configure() {
|
|||
);
|
||||
|
||||
$menu_options = menu_get_menus();
|
||||
$form['menu_default_node_menu'] = array('#type' => 'select',
|
||||
$form['menu_default_node_menu'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Default menu for content'),
|
||||
'#default_value' => variable_get('menu_default_node_menu', 'primary-links'),
|
||||
'#options' => $menu_options,
|
||||
'#description' => t('Choose the menu to be the default in the menu options in the content authoring form.'),
|
||||
);
|
||||
|
||||
$secondary_options = array('secondary-links' => $menu_options['secondary-links'], 'primary-links' => $menu_options['primary-links']);
|
||||
$primary = variable_get('menu_primary_links_source', 'primary-links');
|
||||
$primary_options = array_merge($menu_options, array('' => t('No primary links')));
|
||||
$form['menu_primary_links_source'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Source for the primary links'),
|
||||
'#default_value' => $primary,
|
||||
'#options' => $primary_options,
|
||||
'#tree' => FALSE,
|
||||
'#description' => t('Select what should be displayed as the primary links.'),
|
||||
);
|
||||
|
||||
$secondary_options = array_merge($menu_options, array('' => t('No secondary links')));
|
||||
$form["menu_secondary_links_source"] = array(
|
||||
'#type' => 'radios',
|
||||
'#type' => 'select',
|
||||
'#title' => t('Source for the secondary links'),
|
||||
'#default_value' => variable_get('menu_secondary_links_source', 'secondary-links'),
|
||||
'#options' => $secondary_options,
|
||||
'#tree' => FALSE,
|
||||
'#description' => t('Select what should be displayed as the secondary links. If %primary is chosen, the children of the active primary menu link (if any) will be shown instead of the links in the %secondary menu.', array('%secondary' => $menu_options['secondary-links'], '%primary' => $menu_options['primary-links'])),
|
||||
'#description' => t('Select what should be displayed as the secondary links. You can choose the same menu for secondary links as for primary links (currently %primary). If you do this, the children of the active primary menu link will be displayed as secondary links.', array('%primary' => $primary_options[$primary])),
|
||||
);
|
||||
|
||||
return system_settings_form($form);
|
||||
|
|
|
@ -1703,33 +1703,6 @@ function system_update_6020() {
|
|||
*/
|
||||
function system_update_6021() {
|
||||
$ret = array('#finished' => 0);
|
||||
// Multi-part update
|
||||
if (!isset($_SESSION['system_update_6021'])) {
|
||||
db_add_field($ret, 'menu', 'converted', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'));
|
||||
$_SESSION['system_update_6021_max'] = db_result(db_query('SELECT COUNT(*) FROM {menu}'));
|
||||
$_SESSION['menu_menu_map'] = array(1 => 'navigation');
|
||||
// 0 => FALSE is for new menus, 1 => FALSE is for the navigation.
|
||||
$_SESSION['menu_item_map'] = array(0 => FALSE, 1 => FALSE);
|
||||
if ($secondary = variable_get('menu_secondary_menu', 0)) {
|
||||
$_SESSION['menu_menu_map'][$secondary] = 'secondary-links';
|
||||
$_SESSION['menu_item_map'][$secondary] = FALSE;
|
||||
}
|
||||
if ($primary = variable_get('menu_primary_menu', 0)) {
|
||||
$_SESSION['menu_menu_map'][$primary] = 'primary-links';
|
||||
$_SESSION['menu_item_map'][$primary] = FALSE;
|
||||
if ($primary == $secondary) {
|
||||
variable_set('menu_secondary_links_source', 'primary-links');
|
||||
}
|
||||
}
|
||||
$table = array(
|
||||
'fields' => array(
|
||||
'menu_name' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
|
||||
'title' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
|
||||
'description' => array('type' => 'text', 'not null' => FALSE),
|
||||
),
|
||||
'primary key' => array('menu_name'),
|
||||
);
|
||||
db_create_table($ret, 'menu_custom', $table);
|
||||
$menus = array(
|
||||
'navigation' => array(
|
||||
'menu_name' => 'navigation',
|
||||
|
@ -1747,15 +1720,23 @@ function system_update_6021() {
|
|||
'description' => 'Secondary links are often used for pages like legal notices, contact details, and other secondary navigation items that play a lesser role than primary links',
|
||||
),
|
||||
);
|
||||
// Save user-defined titles.
|
||||
foreach (array($primary, $secondary) as $mid) {
|
||||
if ($item = db_fetch_array(db_query('SELECT * FROM {menu} WHERE mid = %d', $mid))) {
|
||||
$menus[$_SESSION['menu_menu_map'][$mid]]['title'] = $item['title'];
|
||||
}
|
||||
}
|
||||
foreach ($menus as $menu) {
|
||||
db_query("INSERT INTO {menu_custom} (menu_name, title, description) VALUES ('%s', '%s', '%s')", $menu);
|
||||
}
|
||||
// Multi-part update
|
||||
if (!isset($_SESSION['system_update_6021'])) {
|
||||
db_add_field($ret, 'menu', 'converted', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'));
|
||||
$_SESSION['system_update_6021_max'] = db_result(db_query('SELECT COUNT(*) FROM {menu}'));
|
||||
$_SESSION['menu_menu_map'] = array(1 => 'navigation');
|
||||
// 0 => FALSE is for new menus, 1 => FALSE is for the navigation.
|
||||
$_SESSION['menu_item_map'] = array(0 => FALSE, 1 => FALSE);
|
||||
$table = array(
|
||||
'fields' => array(
|
||||
'menu_name' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
|
||||
'title' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
|
||||
'description' => array('type' => 'text', 'not null' => FALSE),
|
||||
),
|
||||
'primary key' => array('menu_name'),
|
||||
);
|
||||
db_create_table($ret, 'menu_custom', $table);
|
||||
db_query("INSERT INTO {menu_custom} (menu_name, title, description) VALUES ('%s', '%s', '%s')", $menus['navigation']);
|
||||
$_SESSION['system_update_6021'] = 0;
|
||||
}
|
||||
|
||||
|
@ -1845,10 +1826,73 @@ function system_update_6021() {
|
|||
// every non-alpanumeric character from the menu name.
|
||||
$ret[] = update_sql("DELETE FROM {menu_links} WHERE menu_name IN ('". implode("', '", $_SESSION['menu_bogus_menus']) ."')");
|
||||
}
|
||||
|
||||
$menu_primary_menu = variable_get('menu_primary_menu', 0);
|
||||
// Ensure that we wind up with a system menu named 'primary-links'.
|
||||
if (isset($_SESSION['menu_menu_map'][2])) {
|
||||
// The primary links menu that ships with Drupal 5 has mid = 2. If this
|
||||
// menu hasn't been deleted by the site admin, we use that.
|
||||
$updated_primary_links_menu = 2;
|
||||
}
|
||||
elseif (isset($_SESSION['menu_menu_map'][$menu_primary_menu]) && $menu_primary_menu > 1) {
|
||||
// Otherwise, we use the menu that is currently assigned to the primary
|
||||
// links region of the theme, as long as it exists and isn't the
|
||||
// Navigation menu.
|
||||
$updated_primary_links_menu = $menu_primary_menu;
|
||||
}
|
||||
else {
|
||||
// As a last resort, create 'primary-links' as a new menu.
|
||||
$updated_primary_links_menu = 0;
|
||||
db_query("INSERT INTO {menu_custom} (menu_name, title, description) VALUES ('%s', '%s', '%s')", $menus['primary-links']);
|
||||
}
|
||||
|
||||
if ($updated_primary_links_menu) {
|
||||
// Change the existing menu name to 'primary-links'.
|
||||
$replace = array('%new_name' => 'primary-links', '%desc' => $menus['primary-links']['description'], '%old_name' => $_SESSION['menu_menu_map'][$updated_primary_links_menu]);
|
||||
$ret[] = update_sql(strtr("UPDATE {menu_custom} SET menu_name = '%new_name', description = '%desc' WHERE menu_name = '%old_name'", $replace));
|
||||
$ret[] = update_sql("UPDATE {menu_links} SET menu_name = 'primary-links' WHERE menu_name = '". $_SESSION['menu_menu_map'][$updated_primary_links_menu] ."'");
|
||||
$_SESSION['menu_menu_map'][$updated_primary_links_menu] = 'primary-links';
|
||||
}
|
||||
|
||||
$menu_secondary_menu = variable_get('menu_secondary_menu', 0);
|
||||
// Ensure that we wind up with a system menu named 'secondary-links'.
|
||||
if (isset($_SESSION['menu_menu_map'][$menu_secondary_menu]) && $menu_secondary_menu > 1 && $menu_secondary_menu != $updated_primary_links_menu) {
|
||||
// We use the menu that is currently assigned to the secondary links
|
||||
// region of the theme, as long as (a) it exists, (b) it isn't the
|
||||
// Navigation menu, (c) it isn't the same menu we assigned as the
|
||||
// system 'primary-links' menu above, and (d) it isn't the same menu
|
||||
// assigned to the primary links region of the theme.
|
||||
$updated_secondary_links_menu = $menu_secondary_menu;
|
||||
}
|
||||
else {
|
||||
// Otherwise, create 'secondary-links' as a new menu.
|
||||
$updated_secondary_links_menu = 0;
|
||||
db_query("INSERT INTO {menu_custom} (menu_name, title, description) VALUES ('%s', '%s', '%s')", $menus['secondary-links']);
|
||||
}
|
||||
|
||||
if ($updated_secondary_links_menu) {
|
||||
// Change the existing menu name to 'secondary-links'.
|
||||
$replace = array('%new_name' => 'secondary-links', '%desc' => $menus['secondary-links']['description'], '%old_name' => $_SESSION['menu_menu_map'][$updated_secondary_links_menu]);
|
||||
$ret[] = update_sql(strtr("UPDATE {menu_custom} SET menu_name = '%new_name', description = '%desc' WHERE menu_name = '%old_name'", $replace));
|
||||
$ret[] = update_sql("UPDATE {menu_links} SET menu_name = 'secondary-links' WHERE menu_name = '". $_SESSION['menu_menu_map'][$updated_secondary_links_menu] ."'");
|
||||
$_SESSION['menu_menu_map'][$updated_secondary_links_menu] = 'secondary-links';
|
||||
}
|
||||
|
||||
// Update menu OTF preferences.
|
||||
$mid = variable_get('menu_parent_items', 0);
|
||||
$menu_name = $mid ? $_SESSION['menu_menu_map'][$mid] : 'navigation';
|
||||
$menu_name = ($mid && isset($_SESSION['menu_menu_map'][$mid])) ? $_SESSION['menu_menu_map'][$mid] : 'navigation';
|
||||
variable_set('menu_default_node_menu', $menu_name);
|
||||
variable_del('menu_parent_items');
|
||||
|
||||
// Update the source of the primary and secondary links.
|
||||
$menu_name = ($menu_primary_menu && isset($_SESSION['menu_menu_map'][$menu_primary_menu])) ? $_SESSION['menu_menu_map'][$menu_primary_menu] : '';
|
||||
variable_set('menu_primary_links_source', $menu_name);
|
||||
variable_del('menu_primary_menu');
|
||||
|
||||
$menu_name = ($menu_secondary_menu && isset($_SESSION['menu_menu_map'][$menu_secondary_menu])) ? $_SESSION['menu_menu_map'][$menu_secondary_menu] : '';
|
||||
variable_set('menu_secondary_links_source', $menu_name);
|
||||
variable_del('menu_secondary_menu');
|
||||
|
||||
// Skip the navigation menu - it is handled by the user module.
|
||||
unset($_SESSION['menu_menu_map'][1]);
|
||||
// Update the deltas for all menu module blocks.
|
||||
|
|
Loading…
Reference in New Issue