If you have two active filters and only the second one exposed the default sorting will be the one from the first filter not from the exposed one.
Example we have nodes with an optional field "field_1" we want to sort this alphabetically but have nodes with "field_1" first, this will have first sort: "field_1" DESC then the exposed filter "title" ASC. The result is wrongly having default sort title DESC.
Issue in Code:the issue is caused by line 235 in the "views_plugin_exposed_form.inc" file.
$first_sort = reset($this->view->sort);
this just gets the first sorting it finds thus generating the bug
Proposed fix:
insert after row 235:
foreach($this->view->sort as $k=>$sort){
if($sort->options['exposed']){
$first_sort = $this->view->sort[$k];
break;
}
}
this picks up the default order form the first exposed filter not from the first filter that is applied
Comments
Comment #1
jansan commentedI'm facing the same issue here. Any updates?
Comment #2
dimaboychev commentedThis is also an issue in Drupal 10.Actually this shouldn't be an issue with views in Drupal 10 (it sets default value properly), however I still get the wrong behavior. When switching from date "sort by" to title "sort by" the sort order is passed in the form submit so it's ignoring the default value.