Sort logic is wrong.

Created on 20 December 2024, 2 months ago

Problem/Motivation

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.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

7.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada liquidcms

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024