Commit 4037fa86 authored by webchick's avatar webchick
Browse files

#846524 by aaronbauman, mgifford: Fixed Terms cannot be manually reordered by weight.

parent 9588a5b3
...@@ -284,6 +284,7 @@ function taxonomy_overview_terms($form, &$form_state, $vocabulary) { ...@@ -284,6 +284,7 @@ function taxonomy_overview_terms($form, &$form_state, $vocabulary) {
// An array of the terms to be displayed on this page. // An array of the terms to be displayed on this page.
$current_page = array(); $current_page = array();
$delta = 0;
$term_deltas = array(); $term_deltas = array();
$tree = taxonomy_get_tree($vocabulary->vid); $tree = taxonomy_get_tree($vocabulary->vid);
$term = current($tree); $term = current($tree);
...@@ -292,6 +293,7 @@ function taxonomy_overview_terms($form, &$form_state, $vocabulary) { ...@@ -292,6 +293,7 @@ function taxonomy_overview_terms($form, &$form_state, $vocabulary) {
if (empty($term)) { if (empty($term)) {
break; break;
} }
$delta++;
// Count entries before the current page. // Count entries before the current page.
if ($page && ($page * $page_increment) > $before_entries && !isset($back_step)) { if ($page && ($page * $page_increment) > $before_entries && !isset($back_step)) {
$before_entries++; $before_entries++;
...@@ -392,6 +394,13 @@ function taxonomy_overview_terms($form, &$form_state, $vocabulary) { ...@@ -392,6 +394,13 @@ function taxonomy_overview_terms($form, &$form_state, $vocabulary) {
// Same as above, the depth is modified by javascript, so it's a default_value. // Same as above, the depth is modified by javascript, so it's a default_value.
'#default_value' => $term->depth, '#default_value' => $term->depth,
); );
$form[$key]['weight'] = array(
'#type' => 'weight',
'#delta' => $delta,
'#title_display' => 'invisible',
'#title' => t('Weight for added term'),
'#default_value' => $term->weight,
);
} }
$form[$key]['edit'] = array('#type' => 'link', '#title' => t('edit'), '#href' => 'taxonomy/term/' . $term->tid . '/edit', '#options' => array('query' => drupal_get_destination())); $form[$key]['edit'] = array('#type' => 'link', '#title' => t('edit'), '#href' => 'taxonomy/term/' . $term->tid . '/edit', '#options' => array('query' => drupal_get_destination()));
} }
...@@ -446,8 +455,8 @@ function taxonomy_overview_terms_submit($form, &$form_state) { ...@@ -446,8 +455,8 @@ function taxonomy_overview_terms_submit($form, &$form_state) {
return; return;
} }
$order = array_flip(array_keys($form_state['input'])); // Get the $_POST order. // Sort term order based on weight.
$form_state['values'] = array_merge($order, $form_state['values']); // Update our original form with the new order. uasort($form_state['values'], 'drupal_sort_weight');
$vocabulary = $form['#vocabulary']; $vocabulary = $form['#vocabulary'];
$hierarchy = 0; // Update the current hierarchy type as we go. $hierarchy = 0; // Update the current hierarchy type as we go.
...@@ -562,6 +571,7 @@ function theme_taxonomy_overview_terms($variables) { ...@@ -562,6 +571,7 @@ function theme_taxonomy_overview_terms($variables) {
drupal_add_js(array('taxonomy' => array('backStep' => $back_step, 'forwardStep' => $forward_step)), 'setting'); drupal_add_js(array('taxonomy' => array('backStep' => $back_step, 'forwardStep' => $forward_step)), 'setting');
drupal_add_css(drupal_get_path('module', 'taxonomy') . '/taxonomy.css'); drupal_add_css(drupal_get_path('module', 'taxonomy') . '/taxonomy.css');
} }
drupal_add_tabledrag('taxonomy', 'order', 'sibling', 'term-weight');
$errors = form_get_errors() != FALSE ? form_get_errors() : array(); $errors = form_get_errors() != FALSE ? form_get_errors() : array();
$rows = array(); $rows = array();
...@@ -577,8 +587,9 @@ function theme_taxonomy_overview_terms($variables) { ...@@ -577,8 +587,9 @@ function theme_taxonomy_overview_terms($variables) {
$term['depth']['#attributes']['class'] = array('term-depth'); $term['depth']['#attributes']['class'] = array('term-depth');
$row[0] .= drupal_render($term['parent']) . drupal_render($term['tid']) . drupal_render($term['depth']); $row[0] .= drupal_render($term['parent']) . drupal_render($term['tid']) . drupal_render($term['depth']);
} }
$term['weight']['#attributes']['class'] = array('term-weight');
$row[] = drupal_render($term['weight']);
$row[] = drupal_render($term['edit']); $row[] = drupal_render($term['edit']);
$row = array('data' => $row); $row = array('data' => $row);
$rows[$key] = $row; $rows[$key] = $row;
} }
...@@ -619,7 +630,7 @@ function theme_taxonomy_overview_terms($variables) { ...@@ -619,7 +630,7 @@ function theme_taxonomy_overview_terms($variables) {
$rows[] = array(array('data' => $form['#empty_text'], 'colspan' => '2')); $rows[] = array(array('data' => $form['#empty_text'], 'colspan' => '2'));
} }
$header = array(t('Name'), t('Operations')); $header = array(t('Name'), t('Weight'), t('Operations'));
$output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'taxonomy'))); $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'taxonomy')));
$output .= drupal_render_children($form); $output .= drupal_render_children($form);
$output .= theme('pager', array('tags' => NULL)); $output .= theme('pager', array('tags' => NULL));
......
...@@ -593,29 +593,25 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase { ...@@ -593,29 +593,25 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase {
drupal_static_reset('taxonomy_get_treeterms'); drupal_static_reset('taxonomy_get_treeterms');
list($term1, $term2, $term3) = taxonomy_get_tree($this->vocabulary->vid); list($term1, $term2, $term3) = taxonomy_get_tree($this->vocabulary->vid);
// Change the order to term2, term3, term1. Emulate the reordering done by
// tabledrag.js by changing the page HTML source. Each term has three hidden
// fields, "tid:1:0[tid]", "tid:1:0[parent]", and "tid:1:0[depth]". The
// order of the input fields in the page is used when the form is processed.
$this->drupalGet('admin/structure/taxonomy/' . $this->vocabulary->machine_name); $this->drupalGet('admin/structure/taxonomy/' . $this->vocabulary->machine_name);
$reorder = array(
'tid:' . $term1->tid . ':0' => 'tid:' . $term2->tid . ':0', // Each term has four hidden fields, "tid:1:0[tid]", "tid:1:0[parent]",
'tid:' . $term2->tid . ':0' => 'tid:' . $term3->tid . ':0', // "tid:1:0[depth]", and "tid:1:0[weight]". Change the order to term2,
'tid:' . $term3->tid . ':0' => 'tid:' . $term1->tid . ':0', // term3, term1 by setting weight property, make term3 a child of term2 by
); // setting the parent and depth properties, and update all hidden fields.
$this->drupalSetContent(strtr($this->drupalGetContent(), $reorder));
// Make term3 a child of term2, and update all hidden fields.
$edit = array( $edit = array(
'tid:' . $term2->tid . ':0[tid]' => $term2->tid, 'tid:' . $term2->tid . ':0[tid]' => $term2->tid,
'tid:' . $term2->tid . ':0[parent]' => 0, 'tid:' . $term2->tid . ':0[parent]' => 0,
'tid:' . $term2->tid . ':0[depth]' => 0, 'tid:' . $term2->tid . ':0[depth]' => 0,
'tid:' . $term2->tid . ':0[weight]' => 0,
'tid:' . $term3->tid . ':0[tid]' => $term3->tid, 'tid:' . $term3->tid . ':0[tid]' => $term3->tid,
'tid:' . $term3->tid . ':0[parent]' => $term2->tid, 'tid:' . $term3->tid . ':0[parent]' => $term2->tid,
'tid:' . $term3->tid . ':0[depth]' => 1, 'tid:' . $term3->tid . ':0[depth]' => 1,
'tid:' . $term3->tid . ':0[weight]' => 1,
'tid:' . $term1->tid . ':0[tid]' => $term1->tid, 'tid:' . $term1->tid . ':0[tid]' => $term1->tid,
'tid:' . $term1->tid . ':0[parent]' => 0, 'tid:' . $term1->tid . ':0[parent]' => 0,
'tid:' . $term1->tid . ':0[depth]' => 0, 'tid:' . $term1->tid . ':0[depth]' => 0,
'tid:' . $term1->tid . ':0[weight]' => 2,
); );
$this->drupalPost(NULL, $edit, t('Save')); $this->drupalPost(NULL, $edit, t('Save'));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment