Currently, file_metadata_table_sort() has a special-case for if you're trying to sort on 'cid', even though that's now a column not handled natively by this module at all. ;) That brings up the interesting question of how sorting should work in case another module is altering a new column into place. I haven't actually thought about this much, but I wanted to open an issue about it so I don't forget. ;)

CommentFileSizeAuthor
#2 1867100.patch6.09 KBjthorson

Comments

jthorson’s picture

One approach would be to add another parameter to hook_file_metadata_table_metadata(), indicating whether a field should be considered numeric or string-based.

So instead of:

function hook_file_metadata_table_metadata() {
  return array(
  'cid' => 'Comment ID'
  );
}

We could use:

function hook_file_metadata_table_metadata() {
  return array(
  'cid' => array(
    'title' => 'Comment ID',
    'sort' => 'numeric',
  );
}

This would require minor tweaks to file_metadata_table_metadata() to have it store the sort parameters as well ... in which case I would rename the function file_metadata_table_types(), and create a new file_metadata_table_metadata() wrapper function which returns only $key => $type['title'] (identical structure to the existing function today).

After these changes, the sort function could be modified as follows:

  $metadata = file_metadata_table_types();
  if ($metadata[$on]['sort'] == 'numeric') {
    $function = "(\$a['{$on}'] > \$b['{$on}']);";
  }
  // For other fields, sort by string value.
  else {
    $function = "strcmp(\$a['{$on}'],\$b['{$on}']);";
  }
jthorson’s picture

Status: Active » Needs review
StatusFileSize
new6.09 KB

Implemented as described above.

jthorson’s picture

Status: Needs review » Fixed

Committed as b71041f.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jthorson’s picture

Project: Attached Files Metadata Table » Extended File Field

Module name change.

  • Commit b71041f on 7.x-1.x, empty-file-2150029 by jthorson:
    Issue #1867100 by jthorson: Improved sorting, introduced...