diff --git modules/toolbar/toolbar.css modules/toolbar/toolbar.css index d530e8b..634a40c 100644 --- modules/toolbar/toolbar.css +++ modules/toolbar/toolbar.css @@ -161,6 +161,49 @@ div#toolbar div.toolbar-shortcuts span.icon { -webkit-border-radius: 5px; } +div#toolbar a#toolbar-customize { + float: right; +} + +div.toolbar-add-to-shortcuts a { + min-width: 12px; + height: 12px; + background: url(toolbar.png) no-repeat -50px -60px; + display: block; + text-decoration: none; +} + +div.toolbar-add-to-shortcuts a span.icon { + display: block; + width: 12px; + background: url(toolbar.png) no-repeat -50px -60px; + height: 12px; + float: left; +} + +div.toolbar-add-to-shortcuts a:hover span.icon { + background-position: -50px -72px; +} + +div.toolbar-add-to-shortcuts a span.text { + float: left; + 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-radius-topright: 5px; + -webkit-border-radius-bottomright: 5px; +} + /** * IE 6 Fixes. * diff --git modules/toolbar/toolbar.install modules/toolbar/toolbar.install index 628893a..0a411bc 100644 --- modules/toolbar/toolbar.install +++ modules/toolbar/toolbar.install @@ -18,7 +18,7 @@ function toolbar_install() { ->fields(array( 'menu_name' => 'admin_shortcuts', 'title' => $t('Administration shortcuts'), - 'description' => $t('The Admininstration shortcuts menu contains commonly used links for administrative tasks.') + 'description' => $t('The Administration shortcuts menu contains commonly used links for administrative tasks.') )) ->execute(); diff --git modules/toolbar/toolbar.module modules/toolbar/toolbar.module index 28371ed..7bcf72f 100644 --- modules/toolbar/toolbar.module +++ modules/toolbar/toolbar.module @@ -7,6 +7,27 @@ */ /** + * Implement hook_menu(). + */ +function toolbar_menu() { + $items = array(); + $items['admin/config/shortcuts/add-link'] = array( + 'title' => 'Add link', + 'page callback' => 'toolbar_shortcut_add_link', + 'access arguments' => array('administer menu'), + 'type' => MENU_CALLBACK, + ); + $items['admin/config/shortcuts/edit'] = array( + 'page callback' => 'toolbar_shortcut_edit_links', + 'page arguments' => array(4), + 'access arguments' => array('administer menu'), + 'type' => MENU_CALLBACK, + ); + + return $items; +} + +/** * Implementation of hook_permission(). */ function toolbar_permission() { @@ -27,9 +48,28 @@ function toolbar_theme($existing, $type, $theme, $path) { 'template' => 'toolbar', 'path' => drupal_get_path('module', 'toolbar'), ); + + $items['add_to_shortcuts_button'] = array ( + 'arguments' => array('link' => '', 'name' => '', 'token' => ''), + ); return $items; } +function theme_add_to_shortcuts_button($link, $name, $token) { + $query = array( + 'link' => $link, + 'name' => $name, + 'token' => $token, + ); + + $output = '
'; + $link_txt = '' . t('Add to shortcuts') . ''; + $output .= l($link_txt, 'admin/config/shortcuts/add-link', array('query' => $query, 'html' => TRUE)); + $output .= '
'; + + return $output; +} + /** * Implement hook_page_build(). * @@ -39,10 +79,94 @@ function toolbar_page_build(&$page) { if (user_access('access toolbar')) { $page['page_top']['toolbar'] = toolbar_build(); } + if (user_access('administer menu')) { + // $_GET['q'] is the unaliased version. + $get = $_GET; + unset($get['q']); + $link = $_GET['q']; + if (!empty($get)) { + $link .= '?' . http_build_query($get); + } + + $page['add_to_shortcuts_button'] = array( + '#theme' => 'add_to_shortcuts_button', + '#link' => $link, + '#name' => drupal_get_title(), + '#token' => drupal_get_token('toolbar-add-to-shortcuts'), + ); + } } /** - * Implement hook_preprocess_page(). + * Menu callback: Add a link to the shortcuts menu. + */ +function toolbar_shortcut_add_link() { + if (isset($_REQUEST['token']) && drupal_valid_token($_REQUEST['token'], 'toolbar-add-to-shortcuts')) { + $link = array( + 'link_title' => $_GET['name'], + 'link_path' => $_GET['link'], + ); + + // Passed by reference, fills in the contents of $link + if (toolbar_save_link_to_shortcuts($link)) { + drupal_set_message(t('Added a shortcut for %title.', array('%title' => $link['link_title']))); + drupal_goto('admin/structure/menu/manage/' . $link['menu_name']); + } + } +} + +/** + * Adds a link to the shortcuts menu. + * + * @param $menu_link + * An unsaved array in the format received by menu_link_save. + * + * @param $menu_name + * An optional menu name to save the newly created shortcut to. If not + * provided will be defined in toolbar_shortcuts_menu_name. + * + * @return array + * The saved menu item. + */ +function toolbar_save_link_to_shortcuts(&$menu_link, $menu_name = NULL) { + + $menu_link['mlid'] = 0; + if (empty($menu_name)) { + $menu_name = toolbar_shortcuts_menu_name(); + } + + $menu_link['menu_name'] = $menu_name; + + // Add some default values to the requested menu link. + $menu_link += array( + 'plid' => 0, + 'module' => 'menu', + ); + + // Put the new link at the end of the list by default. + if (!isset($menu_link['weight'])) { + $menu_link['weight'] = (int)db_query('SELECT MAX(weight) FROM {menu_links} WHERE menu_name = :menu AND plid = :plid', array(':menu' => $menu_link['menu_name'], ':plid' => $menu_link['plid']))->fetchField() + 1; + } + + // Save the link and return the result. + return menu_link_save($menu_link); +} + +/** + * Forwards the user to the appriate menu for editing. + * + * This function looks useless but is here to allow contributed modules to + * override where the link goes. + * + * @param $menu_name + * The name of the menu which contains the shortcuts to be edited. + */ +function toolbar_shortcut_edit_links($menu_name) { + drupal_goto('admin/structure/menu/manage/' . $menu_name); +} + +/** + * Implement hook_preprocess_html(). * * Add some page classes, so global page theming can adjust to the toolbar. */ @@ -52,6 +176,16 @@ function toolbar_preprocess_html(&$vars) { } } + +/** + * Implement hook_preprocess_page(). + * + * Add the shortcut link. + */ +function toolbar_preprocess_page(&$vars) { + $vars['add_to_shortcuts_button'] = !empty($vars['page']['add_to_shortcuts_button']) ? drupal_render($vars['page']['add_to_shortcuts_button']) : ''; +} + /** * Build the admin menu as a structured array ready for drupal_render(). */ @@ -102,18 +236,32 @@ function toolbar_build() { ); // Add convenience shortcut links. - $shortcuts = menu_tree_all_data('admin_shortcuts'); + $shortcuts = menu_tree_all_data(toolbar_shortcuts_menu_name()); $shortcuts = toolbar_menu_navigation_links($shortcuts); $build['toolbar_shortcuts'] = array( - '#theme' => 'links', - '#links' => $shortcuts, - '#attributes' => array('id' => 'toolbar-shortcuts'), + 'shortcuts' => array( + '#theme' => 'links', + '#links' => $shortcuts, + '#attributes' => array('id' => 'toolbar-shortcuts'), + ), ); + if (user_access('administer menu')) { + $build['toolbar_shortcuts']['configure'] = array( + '#markup' => l(t('edit shortcuts'), 'admin/config/shortcuts/edit/' . toolbar_shortcuts_menu_name(), array('attributes' => array('id' => 'toolbar-customize'))), + ); + } return $build; } /** + * Returns the name of the menu that has the current user's toolbar shortcuts. + */ +function toolbar_shortcuts_menu_name() { + return variable_get('shortcut_menu', 'admin_shortcuts'); +} + +/** * Get only the top level items below the 'admin' path. */ function toolbar_get_menu_tree() { diff --git modules/toolbar/toolbar.png modules/toolbar/toolbar.png index ffe41ff..391d2e7 100644 Binary files modules/toolbar/toolbar.png and modules/toolbar/toolbar.png differ diff --git themes/seven/page.tpl.php themes/seven/page.tpl.php index afc955e..b34f3c6 100644 --- themes/seven/page.tpl.php +++ themes/seven/page.tpl.php @@ -4,6 +4,7 @@

+
diff --git themes/seven/style.css themes/seven/style.css index e2d25a0..08c1c36 100644 --- themes/seven/style.css +++ themes/seven/style.css @@ -735,3 +735,10 @@ body.overlay #page { body.overlay #block-system-main { padding: 20px; } + +/* Shortcut theming */ +div.toolbar-add-to-shortcuts { + float: left; + margin-left: 6px; + margin-top: 6px; +}