Example: you want to allow the user to sort by either most recent or by title. Using one or the other as an exposed sort works fine, but if you try to expose both, then the 2nd sort is never used even if it's the one that's selected.

So if the first sort is "created date" and the 2nd sort is "title" and both are exposed, if the user selects "title" as the sort, it will still just sort by "created date".

Here's a view export to reproduce:

$view = new view();
$view->name = 'test_sort_view';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'efq_node';
$view->human_name = 'Test Sort view';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Field: Node: Node ID */
$handler->display->display_options['fields']['nid']['id'] = 'nid';
$handler->display->display_options['fields']['nid']['table'] = 'efq_node';
$handler->display->display_options['fields']['nid']['field'] = 'nid';
/* Sort criterion: Node: Date created */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'efq_node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
$handler->display->display_options['sorts']['created']['exposed'] = TRUE;
$handler->display->display_options['sorts']['created']['expose']['label'] = 'Most Recent';
/* Sort criterion: Node: Title */
$handler->display->display_options['sorts']['title']['id'] = 'title';
$handler->display->display_options['sorts']['title']['table'] = 'efq_node';
$handler->display->display_options['sorts']['title']['field'] = 'title';
$handler->display->display_options['sorts']['title']['order'] = 'DESC';
$handler->display->display_options['sorts']['title']['exposed'] = TRUE;
$handler->display->display_options['sorts']['title']['expose']['label'] = 'Alphabetical';

CommentFileSizeAuthor
#4 multiple-exposed-sorts-1923576-4.diff2.85 KBDerimagia
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mcrittenden’s picture

Just wanted to add that this is broken whether you're using Mongo or MySQL backend. I can reproduce it by importing the above view on a fresh Drupal install using just MySQL as well as on a production site using Mongo.

mcrittenden’s picture

Notes from IRC:

(01:47:59 PM) mcrittenden: dawehner: any pointers on where I could look? I'm happy to dig in myself, just didn't know which of the tons of inc files to check out
(01:48:27 PM) mcrittenden: dawehner: one of the efq_views_handler_sort_*.inc files?
(01:48:55 PM) dawehner: mcrittenden: i would have guessed that the problem might be in the efq query plugin
(01:50:00 PM) mcrittenden: dawehner: maybe in this function in that plugin? https://gist.github.com/5154480
(01:50:44 PM) dawehner: mcrittenden: I guess this function is stilled called multiple times?
(01:50:54 PM) dawehner: mcrittenden: maybe efq itself have issues with multiple sorts
(01:50:59 PM) mcrittenden: dawehner: not sure, but if this is as good a place as any to start looking, then I'll dig in from here
(01:51:00 PM) dawehner: but yeah this is just a 100% guess
(01:51:14 PM) mcrittenden: I'll ping you if I can find anything. thanks for the pointer!
(01:51:17 PM) mcrittenden: dawehner++
(01:51:20 PM) dawehner: mcrittenden: it would be certainly interesting for you to just build a efq which reproduces what you have configured in views
(01:51:58 PM) mcrittenden: dawehner: interesting. I'll see if I can extract the efq that efq_views is using to debug from there
(01:52:38 PM) dawehner: mcrittenden: i guess you could serialize the object and unserialize this object, just as example

jcsnyder’s picture

Not sure if I'm misreading this, but multiple exposed sort criteria is "not supported" in regular views module. I was on a hunt to find a workaround when I found this thread.

Derimagia’s picture

Issue summary: View changes
FileSize
2.85 KB

This isn't an issue with default views.

It looks like the issue is that Views builds the sort criteria (in view::build) which calls the query handlers of all the exposed sorts. Then, later in view:build, Views builds allows exposed items to alter the query (This is where the actual sort query should be called). Default views uses an array to handle the order by, but in efq_views the efq itself is being altered.

I attached a patch to try to resolve this which uses an array similiar to default views. This array is cleared out by views itself when exposed form is allowed to alter the query.

Derimagia’s picture

Status: Active » Needs review