diff options
Diffstat (limited to 'modules/menu')
-rw-r--r-- | modules/menu/menu.admin.inc | 2 | ||||
-rw-r--r-- | modules/menu/menu.admin.js | 75 | ||||
-rw-r--r-- | modules/menu/menu.install | 22 | ||||
-rw-r--r-- | modules/menu/menu.js | 1 | ||||
-rw-r--r-- | modules/menu/menu.module | 20 | ||||
-rw-r--r-- | modules/menu/menu.test | 12 |
6 files changed, 86 insertions, 46 deletions
diff --git a/modules/menu/menu.admin.inc b/modules/menu/menu.admin.inc index d9b98ccbe..5e8f08d57 100644 --- a/modules/menu/menu.admin.inc +++ b/modules/menu/menu.admin.inc @@ -679,7 +679,7 @@ function menu_configure() { '#empty_option' => t('No Secondary links'), '#options' => $menu_options, '#tree' => FALSE, - '#description' => t('Select the source for the Secondary links. An advanced option allows you to use the same source for both Main links (currently %main) and Secondary links: if your source menu has two levels of hierarchy, the top level menu links will appear in the Main links, and the children of the active link will appear in the Secondary links.', array('%main' => $main ? $menu_options[$main] : 'none')), + '#description' => t('Select the source for the Secondary links. An advanced option allows you to use the same source for both Main links (currently %main) and Secondary links: if your source menu has two levels of hierarchy, the top level menu links will appear in the Main links, and the children of the active link will appear in the Secondary links.', array('%main' => $main ? $menu_options[$main] : t('none'))), ); return system_settings_form($form); diff --git a/modules/menu/menu.admin.js b/modules/menu/menu.admin.js index 15bc2e7c7..4fa094e71 100644 --- a/modules/menu/menu.admin.js +++ b/modules/menu/menu.admin.js @@ -1,47 +1,46 @@ - (function ($) { - Drupal.behaviors.menuChangeParentItems = { - attach: function (context, settings) { - $('fieldset#edit-menu input').each(function () { - $(this).change(function () { - // Update list of available parent menu items. - Drupal.menu_update_parent_list(); - }); +Drupal.behaviors.menuChangeParentItems = { + attach: function (context, settings) { + $('fieldset#edit-menu input').each(function () { + $(this).change(function () { + // Update list of available parent menu items. + Drupal.menu_update_parent_list(); }); - } + }); } +}; - /** - * Function to set the options of the menu parent item dropdown. - */ - Drupal.menu_update_parent_list = function () { - var values = []; +/** + * Function to set the options of the menu parent item dropdown. + */ +Drupal.menu_update_parent_list = function () { + var values = []; - $('input:checked', $('fieldset#edit-menu')).each(function () { - // Get the names of all checked menus. - values.push(Drupal.checkPlain($.trim($(this).val()))); - }); + $('input:checked', $('fieldset#edit-menu')).each(function () { + // Get the names of all checked menus. + values.push(Drupal.checkPlain($.trim($(this).val()))); + }); - var url = Drupal.settings.basePath + 'admin/structure/menu/parents'; - $.ajax({ - url: location.protocol + '//' + location.host + url, - type: 'POST', - data: {'menus[]' : values}, - dataType: 'json', - success: function (options) { - // Save key of last selected element. - var selected = $('fieldset#edit-menu #edit-menu-parent :selected').val(); - // Remove all exisiting options from dropdown. - $('fieldset#edit-menu #edit-menu-parent').children().remove(); - // Add new options to dropdown. - jQuery.each(options, function(index, value) { - $('fieldset#edit-menu #edit-menu-parent').append( - $('<option ' + (index == selected ? ' selected="selected"' : '') + '></option>').val(index).text(value) - ); - }); - } - }); - } + var url = Drupal.settings.basePath + 'admin/structure/menu/parents'; + $.ajax({ + url: location.protocol + '//' + location.host + url, + type: 'POST', + data: {'menus[]' : values}, + dataType: 'json', + success: function (options) { + // Save key of last selected element. + var selected = $('fieldset#edit-menu #edit-menu-parent :selected').val(); + // Remove all exisiting options from dropdown. + $('fieldset#edit-menu #edit-menu-parent').children().remove(); + // Add new options to dropdown. + jQuery.each(options, function(index, value) { + $('fieldset#edit-menu #edit-menu-parent').append( + $('<option ' + (index == selected ? ' selected="selected"' : '') + '></option>').val(index).text(value) + ); + }); + } + }); +}; })(jQuery); diff --git a/modules/menu/menu.install b/modules/menu/menu.install index a7e43379e..7877b996d 100644 --- a/modules/menu/menu.install +++ b/modules/menu/menu.install @@ -183,6 +183,28 @@ function menu_update_7002(&$sandbox) { } } /** + * Add missing custom menus to active menus list. + */ +function menu_update_7003(&$sandbox) { + // Make sure all custom menus are present in the active menus variable so that + // their items may appear in the active trail. + // @see menu_set_active_menu_names() + $active_menus = variable_get('menu_default_active_menus', array_keys(menu_list_system_menus())); + $update_variable = FALSE; + foreach (menu_get_names() as $menu_name) { + if (!in_array($menu_name, $active_menus) && (strpos($menu_name, 'menu-') === 0)) { + $active_menus[] = $menu_name; + $update_variable = TRUE; + } + } + if ($update_variable) { + variable_set('menu_default_active_menus', $active_menus); + } + // Clear the menu cache. + cache_clear_all(NULL, 'cache_menu'); +} + +/** * @} End of "defgroup updates-7.x-extra" * The next series of updates should start at 8000. */ diff --git a/modules/menu/menu.js b/modules/menu/menu.js index 40c1bfe95..ff4ef1e17 100644 --- a/modules/menu/menu.js +++ b/modules/menu/menu.js @@ -1,4 +1,3 @@ - (function ($) { Drupal.behaviors.menuFieldsetSummaries = { diff --git a/modules/menu/menu.module b/modules/menu/menu.module index c91486731..40614a162 100644 --- a/modules/menu/menu.module +++ b/modules/menu/menu.module @@ -268,6 +268,15 @@ function menu_save($menu) { switch ($status) { case SAVED_NEW: + // Make sure the menu is present in the active menus variable so that its + // items may appear in the menu active trail. + // @see menu_set_active_menu_names() + $active_menus = variable_get('menu_default_active_menus', array_keys(menu_get_menus())); + if (!in_array($menu['menu_name'], $active_menus)) { + $active_menus[] = $menu['menu_name']; + variable_set('menu_default_active_menus', $active_menus); + } + module_invoke_all('menu_insert', $menu); break; @@ -305,6 +314,15 @@ function menu_delete($menu) { // Delete all links from the menu. menu_delete_links($menu['menu_name']); + // Remove menu from active menus variable. + $active_menus = variable_get('menu_default_active_menus', array_keys(menu_get_menus())); + foreach ($active_menus as $i => $menu_name) { + if ($menu['menu_name'] == $menu_name) { + unset($active_menus[$i]); + variable_set('menu_default_active_menus', $active_menus); + } + } + // Delete the custom menu. db_delete('menu_custom') ->condition('menu_name', $menu['menu_name']) @@ -614,7 +632,7 @@ function menu_form_node_form_alter(&$form, $form_state) { // menu_parent_options() is goofy and can actually handle either a menu link // or a node type both as second argument. Pick based on whether there is // a link already (menu_node_prepare() sets mlid default to 0). - $options = menu_parent_options(menu_get_menus(), $link['mlid'] ? $link : $type); + $options = menu_parent_options(menu_get_menus(), $link['mlid'] ? $link : $type, $type); // If no possible parent menu items were found, there is nothing to display. if (empty($options)) { return; diff --git a/modules/menu/menu.test b/modules/menu/menu.test index 0edfc47b4..324ba6766 100644 --- a/modules/menu/menu.test +++ b/modules/menu/menu.test @@ -205,7 +205,7 @@ class MenuTestCase extends DrupalWebTestCase { // Add menu links. $item1 = $this->addMenuLink(0, 'node/' . $node1->nid, $menu_name); - $item2 = $this->addMenuLink($item1['mlid'], 'node/' . $node2->nid, $menu_name); + $item2 = $this->addMenuLink($item1['mlid'], 'node/' . $node2->nid, $menu_name, FALSE); $item3 = $this->addMenuLink($item2['mlid'], 'node/' . $node3->nid, $menu_name); $this->assertMenuLink($item1['mlid'], array('depth' => 1, 'has_children' => 1, 'p1' => $item1['mlid'], 'p2' => 0)); $this->assertMenuLink($item2['mlid'], array('depth' => 2, 'has_children' => 1, 'p1' => $item1['mlid'], 'p2' => $item2['mlid'], 'p3' => 0)); @@ -283,7 +283,7 @@ class MenuTestCase extends DrupalWebTestCase { * @param string $menu_name Menu name. * @return array Menu link created. */ - function addMenuLink($plid = 0, $link = '<front>', $menu_name = 'navigation') { + function addMenuLink($plid = 0, $link = '<front>', $menu_name = 'navigation', $expanded = TRUE) { // View add menu link page. $this->drupalGet("admin/structure/menu/manage/$menu_name/add"); $this->assertResponse(200); @@ -294,7 +294,7 @@ class MenuTestCase extends DrupalWebTestCase { 'link_title' => $title, 'description' => '', 'enabled' => TRUE, // Use this to disable the menu and test. - 'expanded' => TRUE, // Setting this to true should test whether it works when we do the std_user tests. + 'expanded' => $expanded, // Setting this to true should test whether it works when we do the std_user tests. 'parent' => $menu_name . ':' . $plid, 'weight' => '0', ); @@ -345,7 +345,7 @@ class MenuTestCase extends DrupalWebTestCase { if (isset($parent)) { // Verify menu link. $title = $parent['link_title']; - $this->assertText($title, 'Parent menu link was displayed'); + $this->assertLink($title, 0, 'Parent menu link was displayed'); // Verify menu link link. $this->clickLink($title); @@ -355,7 +355,7 @@ class MenuTestCase extends DrupalWebTestCase { // Verify menu link. $title = $item['link_title']; - $this->assertText($title, 'Menu link was displayed'); + $this->assertLink($title, 0, 'Menu link was displayed'); // Verify menu link link. $this->clickLink($title); @@ -698,6 +698,8 @@ class MenuNodeTestCase extends DrupalWebTestCase { // Assert that it is not possible to set the parent of the first node to itself or the second node. $this->assertNoOption('edit-menu-parent', 'navigation:'. $item['mlid']); $this->assertNoOption('edit-menu-parent', 'navigation:'. $child_item['mlid']); + // Assert that unallowed Management menu is not available in options. + $this->assertNoOption('edit-menu-parent', 'management:0'); } /** |