diff --git a/core/includes/menu.inc b/core/includes/menu.inc index 9412310..cc19b77 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -3050,6 +3050,20 @@ function menu_link_save(&$item, $existing_item = array(), $parent_candidates = a } $menu_name = $item['menu_name']; + // Find the router_path. Do this early (before inserting the menu link into + // the database) since _menu_find_router_path() can result in a menu rebuild, + // which can potentially overwrite the link we're saving in this function. + if (empty($item['router_path']) || !$existing_item || ($existing_item['link_path'] != $item['link_path'])) { + if ($item['external']) { + $item['router_path'] = ''; + } + else { + // Find the router path which will serve this path. + $item['parts'] = explode('/', $item['link_path'], MENU_MAX_PARTS); + $item['router_path'] = _menu_find_router_path($item['link_path']); + } + } + if (!$existing_item) { $item['mlid'] = db_insert('menu_links') ->fields(array( @@ -3097,17 +3111,6 @@ function menu_link_save(&$item, $existing_item = array(), $parent_candidates = a if ($existing_item && ($item['plid'] != $existing_item['plid'] || $menu_name != $existing_item['menu_name'])) { _menu_link_move_children($item, $existing_item); } - // Find the router_path. - if (empty($item['router_path']) || !$existing_item || ($existing_item['link_path'] != $item['link_path'])) { - if ($item['external']) { - $item['router_path'] = ''; - } - else { - // Find the router path which will serve this path. - $item['parts'] = explode('/', $item['link_path'], MENU_MAX_PARTS); - $item['router_path'] = _menu_find_router_path($item['link_path']); - } - } // If every value in $existing_item is the same in the $item, there is no // reason to run the update queries or clear the caches. We use // array_intersect_assoc() with the $item as the first parameter because @@ -3285,10 +3288,15 @@ function _menu_find_router_path($link_path) { $router_path = $link_path; $parts = explode('/', $link_path, MENU_MAX_PARTS); - $ancestors = menu_get_ancestors($parts); if (empty($menu)) { - // Not during a menu rebuild, so look up in the database. + // Not during a menu rebuild, so look up in the database. To avoid fatal + // errors, rebuild first if the menu masks are missing, as we do in + // menu_get_item(). + if (!variable_get('menu_masks', array())) { + menu_rebuild(); + } + $ancestors = menu_get_ancestors($parts); $router_path = (string) db_select('menu_router') ->fields('menu_router', array('path')) ->condition('path', $ancestors, 'IN') @@ -3297,6 +3305,7 @@ function _menu_find_router_path($link_path) { ->execute()->fetchField(); } elseif (!isset($menu[$router_path])) { + $ancestors = menu_get_ancestors($parts); // Add an empty router path as a fallback. $ancestors[] = ''; foreach ($ancestors as $key => $router_path) { diff --git a/core/modules/shortcut/shortcut.install b/core/modules/shortcut/shortcut.install index 7aee9c9..eb5fb11 100644 --- a/core/modules/shortcut/shortcut.install +++ b/core/modules/shortcut/shortcut.install @@ -26,13 +26,6 @@ function shortcut_install() { 'weight' => -19, ); } - // If Drupal is being installed, rebuild the menu before saving the shortcut - // set, to make sure the links defined above can be correctly saved. (During - // installation, the menu might not have been built at all yet, or it might - // have been built but without the node module's links in it.) - if (drupal_installation_attempted()) { - menu_rebuild(); - } shortcut_set_save($shortcut_set); } diff --git a/core/modules/shortcut/shortcut.test b/core/modules/shortcut/shortcut.test index 322c63f..efae145 100644 --- a/core/modules/shortcut/shortcut.test +++ b/core/modules/shortcut/shortcut.test @@ -9,6 +9,7 @@ * Defines base class for shortcut test cases. */ class ShortcutTestCase extends DrupalWebTestCase { + protected $profile = 'testing'; /** * User with permission to administer shortcuts. @@ -31,9 +32,21 @@ class ShortcutTestCase extends DrupalWebTestCase { protected $set; function setUp() { - parent::setUp('toolbar', 'shortcut'); + parent::setUp('node', 'toolbar'); + + // Enable the Shortcut module separately, so we can guarantee that it will + // be enabled after the Node module. This allows the node-related links in + // shortcut_install() to be created. + module_enable(array('shortcut')); + + // Create Basic page and Article node types. + if ($this->profile != 'standard') { + $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); + $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article')); + } + // Create users. - $this->admin_user = $this->drupalCreateUser(array('access toolbar', 'administer shortcuts', 'view the administration theme', 'create article content', 'create page content', 'access content overview')); + $this->admin_user = $this->drupalCreateUser(array('access toolbar', 'administer shortcuts', 'view the administration theme', 'access content', 'create article content', 'create page content', 'access content overview')); $this->shortcut_user = $this->drupalCreateUser(array('customize shortcut links', 'switch shortcut sets')); // Create a node. @@ -110,6 +123,17 @@ class ShortcutLinksTestCase extends ShortcutTestCase { } /** + * Tests that the default shortcut links appear in the toolbar. + */ + function testDefaultShortcutLinks() { + $this->drupalGet(''); + $this->assertTrue(count($this->set->links), t('Found @count links in the default shortcut set.', array('@count' => count($this->set->links)))); + foreach ($this->set->links as $link) { + $this->assertFieldByXPath('//div[@class="toolbar-shortcuts"]//a[contains(@href, "' . $link['link_path'] . '")]', NULL, t('Shortcut for @href found in the toolbar.', array('@href' => $link['link_path']))); + } + } + + /** * Tests that creating a shortcut works properly. */ function testShortcutLinkAdd() { @@ -150,6 +174,9 @@ class ShortcutLinksTestCase extends ShortcutTestCase { * Tests that the "add to shortcut" link changes to "remove shortcut". */ function testShortcutQuickLink() { + theme_enable(array('seven')); + variable_set('admin_theme', 'seven'); + variable_set('node_admin_theme', TRUE); $this->drupalGet($this->set->links[0]['link_path']); $this->assertRaw(t('Remove from %title shortcuts', array('%title' => $this->set->title)), '"Add to shortcuts" link properly switched to "Remove from shortcuts".'); }