summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAngie Byron2010-10-07 17:31:39 (GMT)
committerAngie Byron2010-10-07 17:31:39 (GMT)
commit800cdcc840ea138ca9c207cb43dcb6300995e4b3 (patch)
treee1081a241483a0d5f8c6a9645759b50e54f711e6
parent07510f71e12a6a057989ffb86cfacc57134a406e (diff)
#700380 by mitchmac, Dave Reid, mfb, Ryan Palmer, justinrandell: Fix sorting in tableselect if #weight is not set.
-rw-r--r--includes/form.inc11
-rw-r--r--modules/node/node.test24
2 files changed, 30 insertions, 5 deletions
diff --git a/includes/form.inc b/includes/form.inc
index 2610c99..235d560 100644
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -2932,12 +2932,12 @@ function theme_tableselect($variables) {
$header = $element['#header'];
if (!empty($element['#options'])) {
// Generate a table row for each selectable item in #options.
- foreach ($element['#options'] as $key => $value) {
+ foreach (element_children($element) as $key) {
$row = array();
$row['data'] = array();
- if (isset($value['#attributes'])) {
- $row += $value['#attributes'];
+ if (isset($element['#options'][$key]['#attributes'])) {
+ $row += $element['#options'][$key]['#attributes'];
}
// Render the checkbox / radio element.
$row['data'][] = drupal_render($element[$key]);
@@ -2991,8 +2991,6 @@ function form_process_tableselect($element) {
$element['#default_value'] = array();
}
- // Sort the options by their #weight if they have a #weight.
- uasort($element['#options'], 'element_sort');
// Create a checkbox or radio for each item in #options in such a way that
// the value of the tableselect element behaves as if it had been of type
// checkboxes or radios.
@@ -3023,6 +3021,9 @@ function form_process_tableselect($element) {
'#ajax' => isset($element['#ajax']) ? $element['#ajax'] : NULL,
);
}
+ if (isset($element['#options'][$key]['#weight'])) {
+ $element[$key]['#weight'] = $element['#options'][$key]['#weight'];
+ }
}
}
}
diff --git a/modules/node/node.test b/modules/node/node.test
index 59b12f0..66d6bf7 100644
--- a/modules/node/node.test
+++ b/modules/node/node.test
@@ -1279,6 +1279,30 @@ class NodeAdminTestCase extends DrupalWebTestCase {
}
/**
+ * Tests that the table sorting works on the content admin pages.
+ */
+ function testContentAdminSort() {
+ $this->drupalLogin($this->admin_user);
+ foreach (array('dd', 'aa', 'DD', 'bb', 'cc', 'CC', 'AA', 'BB') as $prefix) {
+ $this->drupalCreateNode(array('title' => $prefix . $this->randomName(6)));
+ }
+
+ // Compare the rendered HTML node list to a query for the nodes ordered by
+ // title to account for possible database-dependent sort order.
+ $nodes_query = db_select('node', 'n')
+ ->fields('n', array('nid'))
+ ->orderBy('title')
+ ->execute()
+ ->fetchCol();
+
+ $this->drupalGet('admin/content', array('query' => array('sort' => 'asc', 'order' => 'Title')));
+ foreach ($this->xpath('//table/tbody/tr/td/div/input/@value') as $input) {
+ $nodes_form[] = $input;
+ }
+ $this->assertEqual($nodes_query, $nodes_form, 'Nodes are sorted in the form the same as they are in the query.');
+ }
+
+ /**
* Tests content overview with different user permissions.
*
* Taxonomy filters are tested separately.