Index: modules/taxonomy/taxonomy.module =================================================================== RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.module,v retrieving revision 1.330 diff -u -r1.330 taxonomy.module --- modules/taxonomy/taxonomy.module 11 Jan 2007 03:29:15 -0000 1.330 +++ modules/taxonomy/taxonomy.module 2 Feb 2007 15:58:21 -0000 @@ -118,12 +118,14 @@ else { if (arg(0) == 'admin' && arg(1) == 'content' && arg(2) == 'taxonomy' && is_numeric(arg(3))) { $vid = arg(3); - $items[] = array('path' => 'admin/content/taxonomy/'. $vid, + $items[] = array( + 'path' => 'admin/content/taxonomy/'. $vid, 'title' => t('List terms'), - 'callback' => 'taxonomy_overview_terms', - 'callback arguments' => array($vid), + 'callback' => 'drupal_get_form', + 'callback arguments' => array('taxonomy_overview_terms', $vid), 'access' => user_access('administer taxonomy'), - 'type' => MENU_CALLBACK); + 'type' => MENU_CALLBACK + ); $items[] = array('path' => 'admin/content/taxonomy/'. $vid .'/list', 'title' => t('List'), @@ -170,46 +172,174 @@ } /** - * Display a tree of all the terms in a vocabulary, with options to edit - * each one. + * Manage vocabulary terms. + * + * @param $vid + * Vocabulary ID of the vocabulary whose terms are to be managed. + * @param $form_values + * $form_values for the multi-step form. This parameter is automatically added + * by the forms API. + * + * @return $form + * A multi-step form array. */ -function taxonomy_overview_terms($vid) { - $destination = drupal_get_destination(); +function taxonomy_overview_terms($vid, $form_values = NULL) { + $form = array(); - $header = array(t('Name'), t('Operations')); - $vocabulary = taxonomy_get_vocabulary($vid); - if (!$vocabulary) { - return drupal_not_found(); + if (!isset($form_values)) { + $step = 1; + } + else { + $step = $form_values['step'] + 1; + // Forward essential values from step 1 to subsequent steps. + $form['operation'] = array('#type' => 'value', '#value' => $form_values['operation']); + $form['terms'] = array('#type' => 'value', '#value' => $form_values['terms']); + $form['vid'] = array('#type' => 'value', '#value' => $vid); } - drupal_set_title(check_plain($vocabulary->name)); - $start_from = $_GET['page'] ? $_GET['page'] : 0; - $total_entries = 0; // total count for pager - $page_increment = 25; // number of tids per page - $displayed_count = 0; // number of tids shown + $form['step'] = array('#type' => 'hidden', '#value' => $step); - $tree = taxonomy_get_tree($vocabulary->vid); - foreach ($tree as $term) { - $total_entries++; // we're counting all-totals, not displayed - if (($start_from && ($start_from * $page_increment) >= $total_entries) || ($displayed_count == $page_increment)) { - continue; - } - $rows[] = array(str_repeat('--', $term->depth) . ' ' . l($term->name, "taxonomy/term/$term->tid"), l(t('edit'), "admin/content/taxonomy/edit/term/$term->tid", array(), $destination)); - $displayed_count++; // we're counting tids displayed + switch ($step) { + case 1: + $vocabulary = taxonomy_get_vocabulary($vid); + if (!$vocabulary) { + return drupal_not_found(); + } + + drupal_set_title(check_plain($vocabulary->name)); + + $start_from = $_GET['page'] ? $_GET['page'] : 0; + // Total count for pager. + $total_entries = 0; + // Number of tids per page. + $page_increment = 50; + // Number of tids shown. + $displayed_count = 0; + + $destination = drupal_get_destination(); + + $tree = taxonomy_get_tree($vocabulary->vid); + $terms = array(); + foreach ($tree as $term) { + // Count all tids. + $total_entries++; + if (($start_from && ($start_from * $page_increment) >= $total_entries) || ($displayed_count == $page_increment)) { + continue; + } + // Count the tids displayed. + $displayed_count++; + + $terms[$term->tid] = ''; + $form['name'][$term->tid] = array('#value' => l($term->name, "taxonomy/term/$term->tid")); + // Forward depth for use in the theme function. + // @see theme_taxonomy_overview_terms. + $form['depth'][$term->tid] = array('#type' => 'value', '#value' => $term->depth); + // Form element 'operations' not to be confused with element 'operation'. + $form['operations'][$term->tid] = array('#value' => l(t('edit'), "admin/content/taxonomy/edit/term/$term->tid", array(), $destination)); + } + $form['terms'] = array('#type' => 'checkboxes', '#options' => $terms); + + $GLOBALS['pager_page_array'][] = $start_from; // FIXME + $GLOBALS['pager_total'][] = intval($total_entries / $page_increment) + 1; // FIXME + + if ($total_entries >= $page_increment) { + $form['pager'] = array('#value' => theme('pager', NULL, $page_increment)); + } + + $form['perform'] = array( + '#type' => 'fieldset', + '#title' => t('Update options'), + '#prefix' => '
', + '#suffix' => '
' + ); + // Other modules can form alter this array to hook in. + $options = array('delete' => t('Delete')); + + $form['perform']['operation'] = array( + '#type' => 'select', + '#options' => $options, + '#default_value' => 'approve' + ); + $form['perform']['submit'] = array('#type' => 'submit', '#value' => t('Update')); + break; + case 2: + // Use the $form element rather than $form_values for consistency with + // other modules that might hook in. + if ($form['operation']['#value'] == 'delete') { + $form = confirm_form( + $form, + t('Are you sure you want to delete the selected terms?'), + 'admin/content/taxonomy/'. $vid, + t('This will delete all selected terms. This action cannot be undone.'), + t('Delete terms') + ); + } } - if (!$rows) { - $rows[] = array(array('data' => t('No terms available.'), 'colspan' => '2')); + $form['#multistep'] = TRUE; + $form['#redirect'] = FALSE; + + return $form; +} + +/** + * Process the taxonomy_overview_terms form submission. + * @todo Avoid the drupal_goto. + */ +function taxonomy_overview_terms_submit($form, $form_values) { + if ($form_values['step'] == 2 && $form_values['operation'] == 'delete' && $form_values['confirm'] == 1) { + foreach ($form_values['terms'] as $tid) { + taxonomy_del_term($tid); + } + // Ideally, an entry would be made for each term deleted. + drupal_set_message(t('The terms have been deleted.')); + watchdog('taxonomy', t('A mass term deletion operation has been performed.')); + + // Rather than toggling the #redirect of the multi-step form, just use a + // goto. + drupal_goto('admin/content/taxonomy/'. $form_values['vid']); } +} - $GLOBALS['pager_page_array'][] = $start_from; // FIXME - $GLOBALS['pager_total'][] = intval($total_entries / $page_increment) + 1; // FIXME +/** + * Process the taxonomy_overview_terms form submission. + */ +function theme_taxonomy_overview_terms($form) { + $output = ''; + // This form is only displayed during step 1 of the multi-step form. + if ($form['step']['#value'] == 1) { + // Overview table. + $header = array(theme('table_select_header_cell'), t('Name'), t('Operations')); - if ($total_entries >= $page_increment) { - $rows[] = array(array('data' => theme('pager', NULL, $page_increment), 'colspan' => '2')); + $output .= drupal_render($form['perform']); + + if (isset($form['name']) && is_array($form['name'])) { + foreach (element_children($form['name']) as $key) { + $row = array(); + $form['name'][$key]['#value'] = str_repeat('--', $form['depth'][$key]['#value']) .' '. $form['name'][$key]['#value']; + $row[] = drupal_render($form['terms'][$key]); + $row[] = drupal_render($form['name'][$key]); + $row[] = drupal_render($form['operations'][$key]); + $rows[] = $row; + } + } + else { + $rows[] = array(array('data' => t('No terms available.'), 'colspan' => '3')); + } + + $output .= theme('table', $header, $rows); + + if ($form['pager']['#value']) { + $output .= drupal_render($form['pager']); + } } - return theme('table', $header, $rows, array('id' => 'taxonomy')); + // The depth element is no longer required. + unset($form['depth']); + + $output .= drupal_render($form); + + return $output; } /** Index: modules/capitalise/capitalise.info =================================================================== RCS file: modules/capitalise/capitalise.info diff -N modules/capitalise/capitalise.info --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/capitalise/capitalise.info 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,4 @@ +; $Id$ +name = Capitalise +description = Demo module that capitalises all selected term names. +version = "$Name$" Index: modules/capitalise/capitalise.module =================================================================== RCS file: modules/capitalise/capitalise.module diff -N modules/capitalise/capitalise.module --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/capitalise/capitalise.module 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,50 @@ +name = ucfirst($term->name); + $term = (array)$term; + taxonomy_save_term($term); + } + // Rather than toggling the #redirect of the multi-step form, just use a + // goto. + drupal_goto('admin/content/taxonomy/'. $form_values['vid']); + } +}