diff --git modules/shortcut/shortcut.module modules/shortcut/shortcut.module index 6eaa6db..302c995 100644 --- modules/shortcut/shortcut.module +++ modules/shortcut/shortcut.module @@ -625,7 +625,11 @@ function shortcut_renderable_links($shortcut_set = NULL) { * Implements hook_preprocess_page(). */ function shortcut_preprocess_page(&$variables) { - if (shortcut_set_edit_access()) { + // Only display the shortcut link if the user has the ability to edit + // shortcuts and if the page's actual content is being shown (for example, + // we do not want to display it on "access denied" or "page not found" + // pages). + if (shortcut_set_edit_access() && ($item = menu_get_item()) && $item['access']) { $link = $_GET['q']; $query_parameters = drupal_get_query_parameters(); if (!empty($query_parameters)) { diff --git modules/shortcut/shortcut.test modules/shortcut/shortcut.test index 6907707..5a43e44 100644 --- modules/shortcut/shortcut.test +++ modules/shortcut/shortcut.test @@ -187,6 +187,23 @@ class ShortcutLinksTestCase extends ShortcutTestCase { $mlids = $this->getShortcutInformation($saved_set, 'mlid'); $this->assertFalse(in_array($set->links[0]['mlid'], $mlids), 'Successfully deleted a shortcut.'); } + + /** + * Tests that the "Add to shortcuts" link is not displayed on a page not + * found or a page the user does not have access to. + */ + function testNoShortcutLink() { + // Set the theme to seven. The default theme (Garland) does not display + // shortcut links. + variable_set('theme_default', 'seven'); + + $this->drupalGet('page-that-does-not-exist'); + $this->assertNoRaw('add-shortcut', t('Add to shortcuts link was not shown on a page not found.')); + + // The user does not have access to this path. + $this->drupalGet('admin/modules'); + $this->assertNoRaw('add-shortcut', t('Add to shortcuts link was not shown on a page the user does not have access to.')); + } } /**