- Issue created by @liquidcms
Couldnt figure out why my term filter options were not being sorted; but looking at code and it is obvious the logic is reversed.
In FilterWidgetBasethere is a method: processSortedOptions() which sorts the options. It has code to not include the "- Any -" potion in the sorted list and then add that back in later, keeping it at the top. But the code is this:
// Ensure "- Any -" value does not get sorted.
$any_option = FALSE;
if (empty($element['#required'])) {
// We use array_slice to preserve they keys needed to determine the value
// when using a filter (e.g. taxonomy terms).
$any_option = array_slice($options, 0, 1, TRUE);
// Array_slice does not modify the existing array, we need to remove the
// option manually.
unset($options[key($any_option)]);
}
So this checks #required to determine if the ANY option has been added, as setting a filter as being "required" is what adds this option. But the logic is flipped. empty() shouldnt be there.
Patch attached in next comment.
Active
7.0
Code