I'm still kind of new to Drupal but I ran into a problem using theme_table() and finally tracked it down to tablesort_header(). Basically the problem is the same as the one mentioned here.
In short the $cell['data'] is being used in place of the $cell['field'] in the table header so the link is created with &order = $cell['data'] which seems like the wrong variable according to the documentation. It seems wrong since the $cell['field'] is never used. Maybe this is by design but the documentation should be updated. It's also possible that its done this way to hide the actual names of your table fields. But then why even have a 'field' parameter at all?
If this is a bug it sounds like its been around since 4.6x. I've checked the code for 6.8 and 6.9 and it appears in both.
Line 91 tablesort.inc
$cell['data'] = l($cell['data'] . $image, $_GET['q'], array('attributes' => array('title' => $title), 'query' => 'sort='. $ts['sort'] .'&order='. urlencode($cell['data']) . $ts['query_string'], 'html' => TRUE));
Should be:
$cell['data'] = l($cell['data'] . $image, $_GET['q'], array('attributes' => array('title' => $title), 'query' => 'sort='. $ts['sort'] .'&order='. urlencode($cell['field']) . $ts['query_string'], 'html' => TRUE));
Comment | File | Size | Author |
---|---|---|---|
#4 | 363292-fix-tablesort-inc-d6.patch | 1.01 KB | brianV |
#4 | 363292-fix-tablesort-inc.patch | 1.07 KB | brianV |
Comments
Comment #1
thaichaiguy CreditAttribution: thaichaiguy commentedComment #2
mdupontComment #3
danielnolde CreditAttribution: danielnolde commentedI just run accross the same bug, according to Drupal API Docs this still is buggy and NOT fixed for D5, D6 *and* D7. This is really a bug and *not* in line with the specification of table header parameter usage, see
http://api.drupal.org/api/function/theme_table
The plain trivial proposed here is correct, applied in seconds and works for for all versions.
Please commit/include.
Comment #4
brianV CreditAttribution: brianV commentedRolled this into patches for D7 & D6.
Comment #5
Dries CreditAttribution: Dries commentedSpacing is not conform our coding style.
It would be awesome if we could have a test for this.
Comment #6
Heine CreditAttribution: Heine commentedHuh?
From http://api.drupal.org/api/function/tablesort_get_order/6
What is the bug here?
Comment #8
Heine CreditAttribution: Heine commentedComment #9
timtoon CreditAttribution: timtoon commented#4: 363292-fix-tablesort-inc.patch queued for re-testing.