diff -u includes/menu.inc includes/menu.inc --- includes/menu.inc +++ includes/menu.inc @@ -2228,19 +2228,31 @@ } /** + * Returns a list of all links for a menu. + * + * @param $menu_name + * The name of the menu whose links should be returned. + * @return + * An array of menu links. + */ +function menu_load_links($menu_name) { + return db_query("SELECT * FROM {menu_links} WHERE menu_name = :menu_name", array(':menu_name' => $menu_name)); +} + +/** * Deletes all links for a menu. * * @param $menu_name * The name of the menu whose links will be deleted. */ function menu_delete_links($menu_name) { - $links = db_query("SELECT * FROM {menu_links} WHERE menu_name = :menu_name", array(':menu_name' => $menu_name)); + $links = menu_load_links($menu_name); foreach ($links as $link) { // To speed up the deletion process, we reset some link properties that // would trigger re-parenting logic in _menu_delete_item() and // _menu_update_parental_status(). - $link['has_children'] = FALSE; - $link['plid'] = 0; + $link->has_children = FALSE; + $link->plid = 0; _menu_delete_item($link); } } diff -u modules/shortcut/shortcut.admin.inc modules/shortcut/shortcut.admin.inc --- modules/shortcut/shortcut.admin.inc +++ modules/shortcut/shortcut.admin.inc @@ -76,0 +77,27 @@ + +/** + * Menu callback; Creates a new link in the provided shortcut set + * + * After completion, redirects the user back to where they came from. + * + * @param $shortcut_set + * Returned from shortcut_set_load. + * + */ +function shortcut_add_link($shortcut_set) { + if (isset($_REQUEST['token']) && drupal_valid_token($_REQUEST['token'], 'shortcut-add')) { + $link = array( + 'link_title' => $_GET['name'], + 'link_path' => $_GET['link'], + ); + // Really we should test for a dupe here. + $shortcut_set->links[] = $link; + + if (shortcut_set_save($shortcut_set)) { + drupal_set_message(t('Added a shortcut for %title.', array('%title' => $link['link_title']))); + drupal_goto(); + } + } else { + drupal_set_message(t('Unable to add a shortcut for %title.', array('%title' => $link['link_title']))); + } +} \ No newline at end of file diff -u modules/shortcut/shortcut.css modules/shortcut/shortcut.css --- modules/shortcut/shortcut.css +++ modules/shortcut/shortcut.css @@ -22,8 +22,7 @@ div#toolbar div.toolbar-shortcuts ul li a.active:hover, div#toolbar div.toolbar-shortcuts ul li a.active { - background: url(../modules/toolbar/toolbar.png) 0 -20px repeat-x; - background: #555; + background: url(../toolbar/toolbar.png) 0 -20px repeat-x; } div#toolbar div.toolbar-shortcuts span.icon { @@ -37 +36,35 @@ -} \ No newline at end of file +} + +div.toolbar-add-to-shortcuts a span.icon { + display: block; + width: 12px; + background: url(../toolbar/toolbar.png) no-repeat -50px -60px; + height: 12px; + float: left; + margin-left:8px; +} + +div.toolbar-add-to-shortcuts a:hover span.icon { + background-position: -50px -72px; +} + +div.toolbar-add-to-shortcuts a span.text { + float: left; + padding-left:10px; + display: none; +} + +div.toolbar-add-to-shortcuts a:hover span.text { + font-size: 10px; + line-height: 12px; + color: #fff; + background-color: #5f605b; + display: block; + padding-right: 6px; + cursor: pointer; + -moz-border-radius-topright: 5px; + -moz-border-radius-bottomright: 5px; + -webkit-border-top-right-radius: 5px; + -webkit-border-bottom-right-radius: 5px; +} + diff -u modules/shortcut/shortcut.install modules/shortcut/shortcut.install --- modules/shortcut/shortcut.install +++ modules/shortcut/shortcut.install @@ -36,7 +36,7 @@ 'weight' => -19, ), array( - 'link_path' => 'admin', + 'link_path' => 'admin/dashboard', 'link_title' => $t('Dashboard'), 'weight' => -18, ), diff -u modules/shortcut/shortcut.module modules/shortcut/shortcut.module --- modules/shortcut/shortcut.module +++ modules/shortcut/shortcut.module @@ -48,8 +48,8 @@ ); $items['admin/config/system/shortcut/%shortcut_set/add-link'] = array( 'title' => 'Add shortcut', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('shortcut_link_edit', 4), + 'page callback' => 'shortcut_add_link', + 'page arguments' => array(4), 'access callback' => 'shortcut_set_access', 'access arguments' => array(4), 'type' => MENU_LOCAL_ACTION, @@ -113,7 +113,16 @@ * FALSE if the set does not exist. */ function shortcut_set_load($set_name) { - return db_query("SELECT * FROM {shortcut_set} WHERE set_name = :set_name", array(':set_name' => $set_name))->fetchObject(); + $set = db_query("SELECT * FROM {shortcut_set} WHERE set_name = :set_name", array(':set_name' => $set_name))->fetchObject(); + if (!$set) { + return; + } + $set->links = array(); + foreach (menu_load_links($set_name) as $link) { + // This is a WTF, but what to do? menu_link_save() only takes arrays. + $set->links[] = (array)$link; + } + return $set; } /** @@ -330,12 +339,15 @@ $query = array( 'link' => $link, 'name' => drupal_get_title(), + 'token' => drupal_get_token('shortcut-add'), ); + $query += drupal_get_destination(); $shortcut_set = shortcut_default_set($user); + $page['add_to_shortcuts'] = array( '#prefix' => '
', - '#markup' => l('' . t('Add to %shortcut_set_name shortcuts', array('%shortcut_set_name' => $shortcut_set->title)) . '', 'admin/config/system/shortcut/' . $shortcut_set->set_name . '/add-link', array('query' => $query, 'html' => TRUE)), + '#markup' => l('' . t('Add to %shortcut_set_name shortcuts', array('%shortcut_set_name' => $shortcut_set->title)) . '', 'admin/config/system/shortcut/' . $shortcut_set->set_name . '/add-link/', array('query' => $query, 'html' => TRUE)), '#suffix' => '
', ); }