diff -u includes/menu.inc includes/menu.inc --- includes/menu.inc +++ includes/menu.inc @@ -2262,8 +2262,14 @@ * An array of menu links. */ function menu_load_links($menu_name) { - $links = db_query("SELECT * FROM {menu_links} WHERE menu_name = :menu_name", array(':menu_name' => $menu_name))->fetchAll(PDO::FETCH_ASSOC); - foreach ($links as &$link) { + $links = db_select('menu_links', 'ml', array('fetch' => PDO::FETCH_ASSOC)) + ->fields('ml') + ->condition('ml.menu_name', $menu_name) + ->orderBy('weight') + ->execute() + ->fetchAll(); + + foreach ($links as $key => &$link) { $link['options'] = unserialize($link['options']); } return $links; diff -u modules/shortcut/shortcut.admin.inc modules/shortcut/shortcut.admin.inc --- modules/shortcut/shortcut.admin.inc +++ modules/shortcut/shortcut.admin.inc @@ -46,7 +46,7 @@ $default_set = shortcut_default_set($account); $options = array(); foreach ($sets as $name => $set) { - $options[$name] = check_plain($set['title']); + $options[$name] = check_plain($set->title); } // Only administrators can add shortcut sets. @@ -64,12 +64,12 @@ '#type' => 'radios', '#title' => t('Choose a set'), '#options' => $options, - '#default_value' => $current_set['set_name'], + '#default_value' => $current_set->set_name, ); $form['new'] = array( '#type' => 'textfield', - '#description' => t('The new set is created by copying items from the @default set.', array('@default' => $default_set['title'])), + '#description' => t('The new set is created by copying items from the @default set.', array('@default' => $default_set->title)), '#access' => $add_access, ); @@ -93,22 +93,22 @@ $default_set = shortcut_default_set(); $set = array( 'title' => $form_state['values']['new'], - 'links' => menu_links_clone($default_set['links']), + 'links' => menu_links_clone($default_set->links), ); shortcut_set_save($set); $replacements = array( '%user' => $account->name, - '%set_name' => $set['title'], + '%set_name' => $set->title, ); drupal_set_message($account->uid == $user->uid ? t('A new shortcut set called %set_name was created with the default shortcut items. You are now using this set.', $replacements) : t('%user is now using a new shortcut set called %set_name with the default shortcut items.', $replacements)); - $form_state['redirect'] = 'admin/config/system/shortcut/' . $set['set_name']; + $form_state['redirect'] = 'admin/config/system/shortcut/' . $set->set_name; } else { // Switch to a different shortcut set. $set = shortcut_set_load($form_state['values']['set']); $replacements = array( '%user' => $account->name, - '%set_name' => $set['title'], + '%set_name' => $set->title, ); drupal_set_message($account->uid == $user->uid ? t('You are now using the %set_name shortcut set.', $replacements) : t('%user is now using the %set_name shortcut set.', $replacements)); } @@ -154,7 +154,7 @@ */ function shortcut_set_customize($form, &$form_state, $shortcut_set) { $form['set'] = array( - '#markup' => t('Using set "@set"', array('@set' => $set['name'])), + '#markup' => t('Using set "@set"', array('@set' => $shortcut_set->title)), '#prefix' => '

', '#suffix' => '

', '#weight' => -100, @@ -170,10 +170,10 @@ $form['shortcuts']['#tree'] = TRUE; $form['shortcuts']['enabled'] = $form['shortcuts']['disabled'] = array(); - foreach ($set['links'] as $link) { + foreach ($shortcut_set->links as $link) { $mlid = $link['mlid']; $status = $link['hidden'] ? 'disabled' : 'enabled'; - $form['shortcuts'][$status][$mlid]['name']['#markup'] = l($shortcut['link_title'], $shortcut['link_path']); + $form['shortcuts'][$status][$mlid]['name']['#markup'] = l($link['link_title'], $link['link_path']); $form['shortcuts'][$status][$mlid]['weight'] = array( '#type' => 'weight', '#title' => t('Weight'), @@ -189,10 +189,9 @@ '#attributes' => array('class' => array('shortcut-status-select')), ); - $form['shortcuts'][$status][$mlid]['edit']['#markup'] = l(t('edit'), 'admin/config/system/shortcut/' . $set['set_name'] . '/link/' . $mlid); - $form['shortcuts'][$status][$mlid]['delete']['#markup'] = l(t('delete'), 'admin/config/system/shortcut/' . $set['set_name'] . '/link/' . $mlid . '/delete'); + $form['shortcuts'][$status][$mlid]['edit']['#markup'] = l(t('edit'), 'admin/config/system/shortcut/link/' . $mlid); + $form['shortcuts'][$status][$mlid]['delete']['#markup'] = l(t('delete'), 'admin/config/system/shortcut/link/' . $mlid . '/delete'); } - $form['submit'] = array( '#type' => 'submit', '#value' => t('Save Changes'), @@ -208,12 +207,11 @@ foreach ($form_state['values']['shortcuts'] as $status => $links) { foreach ($links as $mlid => $data) { $link = menu_link_load($mlid); - $link['hidden'] = $status == 'enabled' ? FALSE : TRUE; + $link['hidden'] = $status == 'enabled' ? 0 : 1; $link['weight'] = $data['weight']; menu_link_save($link); } } - /* TODO: // Knock an enabled one out if we have to. @@ -269,10 +267,10 @@ )), 'class' => array('toolbar-status', 'toolbar-status-' . $status), ); - foreach (element_children($form[$status]) as $key) { - $shortcut = &$form[$status][$key]; + foreach (element_children($form['shortcuts'][$status]) as $key) { + $shortcut = &$form['shortcuts'][$status][$key]; $row = array(); - $row[] = drupal_render($shortcut['link_title']); + $row[] = drupal_render($shortcut['name']); $row[] = drupal_render($shortcut['weight']); $row[] = drupal_render($shortcut['status']); $row[] = drupal_render($shortcut['edit']); @@ -292,7 +290,7 @@ 'class' => array('toolbar-slot-empty'), ); } - $count_shortcuts = count(element_children($form[$status])); + $count_shortcuts = count(element_children($form['shortcuts'][$status])); if (!empty($count_shortcuts)) { for ($i = 0; $i < min($count_shortcuts, shortcut_max_slots()); $i++) { $rows['empty-' . $i]['class'][] = 'toolbar-slot-hidden'; @@ -301,16 +299,13 @@ } } $header = array(t('Name'), t('Weight'), t('Status'), array('data' => t('Operations'), 'colspan' => 2)); - return theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'shortcuts'))); + $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'shortcuts'))); + $output .= drupal_render($form['submit']); + $output = drupal_render_children($form) . $output; + return $output; } - - - - - - /** * Menu callback; Build the form for adding or editing a shortcut link. * @@ -319,7 +314,8 @@ * @param $form_state * An associative array containing the current state of the form. * @param $shortcut_set - * An array representing the shortcut set that the link is assigned to. + * (optional) + * An object representing the shortcut set that the link is assigned to. * @param $shortcut_link * (optional) An array representing the link that is being edited. If not * set, the form will allow a new link to be created. @@ -329,15 +325,50 @@ * @ingroup forms * @see shortcut_link_edit_submit() */ -function shortcut_link_edit($form, &$form_state, $shortcut_set, $shortcut_link = NULL) { - // TODO: Copy code here. +function shortcut_link_edit($form, &$form_state, $shortcut_set = NULL, $shortcut_link = NULL) { + if (!isset($shortcut_link)) { + $shortcut_link = array('link_title' => t(''), 'link_path' => ''); + drupal_set_title(t('Add new shortcut')); + } + else { + drupal_set_title(t('Editing @shortcut', array('@shortcut' => $shortcut_link['link_title']))); + } + + $form['link_title'] = array( + '#type' => 'textfield', + '#title' => t('Name'), + '#description' => t('The name of the shortcut.'), + '#size' => 40, + '#maxlength' => 255, + '#default_value' => $shortcut_link['link_title'], + ); + + $form['link_path'] = array( + '#type' => 'textfield', + '#title' => t('Path'), + '#description' => t('The path to the shortcut.'), + '#size' => 40, + '#maxlength' => 255, + '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='), + '#default_value' => $shortcut_link['link_path'], + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Save'), + ); + + $form_state['shortcut_link'] = $shortcut_link; + return $form; } /** * Submit handler for the shortcut link editing form. */ function shortcut_link_edit_submit($form, &$form_state) { - // TODO: Copy code here. + $form_state['shortcut_link'] = array_merge($form_state['shortcut_link'], $form_state['values']); + menu_link_save($form_state['shortcut_link']); + $form_state['redirect'] = 'admin/config/system/shortcut'; } /** @@ -381,7 +412,7 @@ 'link_path' => $_GET['link'], ); // Really we should test for a dupe here. - $shortcut_set['links'][] = $link; + $shortcut_set->links[] = $link; if (shortcut_set_save($shortcut_set)) { drupal_set_message(t('Added a shortcut for %title.', array('%title' => $link['link_title']))); diff -u modules/shortcut/shortcut.css modules/shortcut/shortcut.css --- modules/shortcut/shortcut.css +++ modules/shortcut/shortcut.css @@ -1,4 +1,7 @@ /* $Id$ */ +div#toolbar a#toolbar-customize { + float: right; +} div#toolbar div.toolbar-shortcuts ul { padding: 5px 0; diff -u modules/shortcut/shortcut.install modules/shortcut/shortcut.install --- modules/shortcut/shortcut.install +++ modules/shortcut/shortcut.install @@ -17,24 +17,23 @@ $t = get_t(); // Create an initial default shortcut set. - $shortcut_set = array( - 'title' => $t('Default'), - 'links' => array( - array( - 'link_path' => 'node/add', - 'link_title' => $t('Add content'), - 'weight' => -20, - ), - array( - 'link_path' => 'admin/content', - 'link_title' => $t('Find content'), - 'weight' => -19, - ), - array( - 'link_path' => 'admin/dashboard', - 'link_title' => $t('Dashboard'), - 'weight' => -18, - ), + $shortcut_set = new StdClass(); + $shortcut_set->title = $t('Default'); + $shortcut_set->links = array( + array( + 'link_path' => 'node/add', + 'link_title' => $t('Add content'), + 'weight' => -20, + ), + array( + 'link_path' => 'admin/content', + 'link_title' => $t('Find content'), + 'weight' => -19, + ), + array( + 'link_path' => 'admin/dashboard', + 'link_title' => $t('Dashboard'), + 'weight' => -18, ), ); shortcut_set_save($shortcut_set); diff -u modules/shortcut/shortcut.module modules/shortcut/shortcut.module --- modules/shortcut/shortcut.module +++ modules/shortcut/shortcut.module @@ -73,19 +73,19 @@ 'type' => MENU_CALLBACK, 'file' => 'shortcut.admin.inc', ); - $items['admin/config/system/shortcut/%shortcut_set/link/%menu_link'] = array( + $items['admin/config/system/shortcut/link/%menu_link'] = array( 'title' => 'Edit shortcut', 'page callback' => 'drupal_get_form', - 'page arguments' => array('shortcut_link_edit', 4, 6), + 'page arguments' => array('shortcut_link_edit', NULL, 5), 'access callback' => 'shortcut_set_access', 'access arguments' => array(4), 'type' => MENU_CALLBACK, 'file' => 'shortcut.admin.inc', ); - $items['admin/config/system/shortcut/%shorcut_set/link/%menu_link/delete'] = array( + $items['admin/config/system/shortcut/link/%menu_link/delete'] = array( 'title' => 'Delete shortcut', 'page callback' => 'drupal_get_form', - 'page arguments' => array('shortcut_link_delete', 6), + 'page arguments' => array('shortcut_link_delete', 5), 'access callback' => 'shortcut_set_access', 'access arguments' => array(4), 'type' => MENU_CALLBACK, @@ -136,7 +136,7 @@ function shortcut_block_view($delta = '') { if ($delta == 'shortcuts') { $shortcut_set = shortcut_current_displayed_set(); - $data['subject'] = t('@shortcut_set shortcuts', array('@shortcut_set' => $shortcut_set['title'])); + $data['subject'] = t('@shortcut_set shortcuts', array('@shortcut_set' => $shortcut_set->title)); $data['content'] = shortcut_renderable_links($shortcut_set); return $data; } @@ -148,7 +148,7 @@ function shortcut_set_access($shortcut_set) { // Sufficiently-privileged users can edit their currently displayed shortcut // set, but not other sets. Shortcut administrators can edit any set. - return user_access('administer shortcuts') || (user_access('customize shortcut links') && ($current_set = shortcut_current_displayed_set()) && $current_set['set_name'] == $shortcut_set['set_name']); + return user_access('administer shortcuts') || (user_access('customize shortcut links') && ($current_set = shortcut_current_displayed_set()) && $current_set->set_name == $shortcut_set->set_name); } /** @@ -167,18 +167,18 @@ * @param $set_name * The name of the shortcut set to load. * @return - * If the shortcut set exists, an array containing the following keys: + * If the shortcut set exists, a StdClass containing the following properties: * - 'set_name': The internal name of the shortcut set. * - 'title': The title of the shortcut set. * - 'links': An array of links associated with this shortcut set. * If the shortcut set does not exist, the function returns FALSE. */ function shortcut_set_load($set_name) { - $set = db_query("SELECT * FROM {shortcut_set} WHERE set_name = :set_name", array(':set_name' => $set_name))->fetchAssoc(); + $set = db_query("SELECT * FROM {shortcut_set} WHERE set_name = :set_name", array(':set_name' => $set_name))->fetchObject(); if (!$set) { return FALSE; } - $set['links'] = menu_load_links($set_name); + $set->links = menu_load_links($set_name); return $set; } @@ -186,7 +186,7 @@ * Saves a shortcut set. * * @param $shortcut_set - * An array containing the following keys: + * An object containing the following properties: * - 'title': The title of the shortcut set. * - 'set_name': (optional) The internal name of the shortcut set. If * omitted, a new shortcut set will be created, and the 'set_name' key @@ -206,22 +206,22 @@ */ function shortcut_set_save(&$shortcut_set) { // First save the shortcut set itself. - if (isset($shortcut_set['set_name'])) { + if (isset($shortcut_set->set_name)) { $return = drupal_write_record('shortcut_set', $shortcut_set, 'set_name'); } else { - $shortcut_set['set_name'] = shortcut_set_get_unique_name(); + $shortcut_set->set_name = shortcut_set_get_unique_name(); $return = drupal_write_record('shortcut_set', $shortcut_set); } // If links were provided for the set, save them, replacing any that were // there before. - if (isset($shortcut_set['links'])) { - menu_delete_links($shortcut_set['set_name']); - foreach ($shortcut_set['links'] as &$link) { + if (isset($shortcut_set->links)) { + menu_delete_links($shortcut_set->set_name); + foreach ($shortcut_set->links as &$link) { // Do not specifically associate these links with the shortcut module, // since other modules may make them editable via the menu system. // However, we do need to specify the correct menu name. - $link['menu_name'] = $shortcut_set['set_name']; + $link['menu_name'] = $shortcut_set->set_name; menu_link_save($link); } // Make sure that we have a return value, since if the links were updated @@ -247,19 +247,19 @@ function shortcut_set_delete($shortcut_set) { // Make sure not to delete the default set. $default_set = shortcut_default_set(); - if ($shortcut_set['set_name'] == $default_set['set_name']) { + if ($shortcut_set->set_name == $default_set->set_name) { return FALSE; } // First, delete any user assignments for this set, so that each of these // users will go back to using whatever default set applies. db_delete('shortcut_set_users') - ->condition('set_name', $shortcut_set['set_name']) + ->condition('set_name', $shortcut_set->set_name) ->execute(); // Next, delete the menu links for this set. - menu_delete_links($shortcut_set['set_name']); + menu_delete_links($shortcut_set->set_name); // Finally, delete the set itself. $deleted = db_delete('shortcut_set') - ->condition('set_name', $shortcut_set['set_name']) + ->condition('set_name', $shortcut_set->set_name) ->execute(); return (bool) $deleted; } @@ -275,7 +275,7 @@ function shortcut_set_assign_user($shortcut_set, $account) { db_merge('shortcut_set_users') ->key(array('uid' => $account->uid)) - ->fields(array('set_name' => $shortcut_set['set_name'])) + ->fields(array('set_name' => $shortcut_set->set_name)) ->execute(); } @@ -325,7 +325,7 @@ $query->fields('s'); $query->join('shortcut_set_users', 'u', 's.set_name = u.set_name'); $query->condition('u.uid', $account->uid); - $shortcut_set = $query->execute()->fetchAssoc(); + $shortcut_set = $query->execute()->fetchObject(); // Otherwise, use the default set. if (!$shortcut_set) { $shortcut_set = shortcut_default_set($account); @@ -396,7 +396,7 @@ * Returns an array of all shortcut sets, keyed by the set name. */ function shortcut_sets() { - return db_query("SELECT * FROM {shortcut_set}")->fetchAllAssoc('set_name', PDO::FETCH_ASSOC); + return db_query("SELECT * FROM {shortcut_set}")->fetchAllAssoc('set_name'); } /** @@ -414,7 +414,7 @@ if (!isset($shortcut_set)) { $shortcut_set = shortcut_current_displayed_set(); } - return menu_tree($shortcut_set['set_name']); + return menu_tree($shortcut_set->set_name); } /** @@ -440,7 +440,7 @@ $page['add_to_shortcuts'] = array( '#prefix' => '
', - '#markup' => l('' . t('Add to %shortcut_set shortcuts', array('%shortcut_set' => $shortcut_set['title'])) . '', 'admin/config/system/shortcut/' . $shortcut_set['set_name'] . '/add-link-inline', array('query' => $query, 'html' => TRUE)), + '#markup' => l('' . t('Add to %shortcut_set shortcuts', array('%shortcut_set' => $shortcut_set->title)) . '', 'admin/config/system/shortcut/' . $shortcut_set->set_name . '/add-link-inline', array('query' => $query, 'html' => TRUE)), '#suffix' => '
', ); } @@ -449,7 +449,16 @@ $links['#attached'] = array('css' => array(drupal_get_path('module', 'shortcut') . '/shortcut.css')); $links['#prefix'] = '
'; $links['#suffix'] = '
'; - $page['toolbar_drawer'] = $links; + $configure_link = array('#markup' => l(t('edit shortcuts'), 'admin/config/system/shortcut/' . $shortcut_set->set_name, array('attributes' => array('id' => 'toolbar-customize')))); + + $drawrer = array ( + 'shortcuts' => $links, + 'configure' => $configure_link, + ); + + + + $page['toolbar_drawer'] = $drawrer; } /** only in patch2: unchanged: --- /dev/null +++ modules/shortcut/shortcut.admin.css @@ -0,0 +1,14 @@ +/* $Id$ */ + +h4.shortcuts-set, +div.shortcuts-change-set { + display: inline; +} + +.toolbar-slot-hidden { + display: none; +} + +div.form-item-set div.form-item-new { + display: inline; +} only in patch2: unchanged: --- modules/toolbar/toolbar.install +++ /dev/null @@ -1,56 +0,0 @@ - 'admin_shortcuts', - 'title' => $t('Administration shortcuts'), - 'description' => $t('The Administration shortcuts menu contains commonly used links for administrative tasks.'), - ); - menu_save($menu); - - // Add starter convenience shortcuts. - menu_rebuild(); - $items = array( - 'node/add' => 'Add content', - 'admin/content' => 'Find content', - 'admin/dashboard' => 'Dashboard', - ); - $weight = -20; - foreach ($items as $path => $title) { - $link = array( - 'mlid' => 0, - 'link_title' => $title, - 'link_path' => $path, - 'router_path' => $path, - 'menu_name' => 'admin_shortcuts', - 'module' => 'menu', - 'weight' => $weight, - ); - - // Check for an existing menu item before attempting to create a new one. - $menu_link = db_query("SELECT mlid FROM {menu_links} WHERE link_path = :path AND menu_name = :menu_name", array( - ':path' => $link['link_path'], - ':menu_name' => $link['menu_name'] - )) - ->fetchField(); - if (!$menu_link) { - menu_link_save($link); - } - - // Increment weight so items can be displayed in desired order. - $weight++; - } -}