I added 2 views fields to make available the witdh and height of images using the information provided by the file_entity module. This works and I can show the values.

Now I want to make both fields sortable, and I ended up with this code for the sort handler:

 * Field handler to sort by the width of an image.
 * @ingroup views_field_handlers
class views_handler_sort_width extends views_handler_sort {

   * Called to add the sort to a query.
  public function query() {
    // Add the relation to the file_metada table and sort by width.
    $join = new views_join();
    $join->table = 'file_metadata';
    $join->field = 'fid';
    $join->left_table = $this->table_alias;
    $join->left_field = $this->real_field;
    $join->type = 'left';
    // Add the join the the view query.
    $this->query->add_relationship('file_metadata', $join, $this->table_alias);
    $this->query->add_where('file_metadata', 'name', 'width', '=');
    $this->query->add_field('file_metadata', 'value');
    // Add the order by.
    $this->query->add_orderby('file_metadata', 'value', $this->options['order']);


It doesn't work. No sorting occurs, and the order is the same even if I select ASC or DESC. Any ideas on what I might be doing wrong here?

P.S.: I know the metadata is stored serialized.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.