Adapt exposed sorts feature to handle more diverse data structures

Created on 29 November 2022, about 2 years ago
Updated 27 February 2024, 10 months ago

Problem/Motivation

In some situations, the the exposed sort data structure is not saved with a nested "value".

VBO expects:

Array
(
    [sort_by] => Array
        (
            [value] => title
        )

    [sort_order] => Array
        (
            [value] => DESC
        )

)

However sometimes it is saved as

Array
(
    [sort_by] => title
    [sort_order] => DESC
)

So far I've only seen this when working with Gutenberg and I've not been able to isolate how/why VBO has the nested `[value]` data structure.

Marking as a bug, but could be a feature.

Steps to reproduce

Create a VBO block and place in Gutenberg. Sorting is not respected.

Proposed resolution

Have some logic that accomodates different structures.:

          // In some situations, the exposed sort is not passed as a nested `[value]`.
          $sort_by = isset($config['exposed_sort']['sort_by']['value']) ? $config['exposed_sort']['sort_by']['value'] : $config['exposed_sort']['sort_by'];
          $sort_order = isset($config['exposed_sort']['sort_by']['value']) ? $config['exposed_sort']['sort_by']['value'] : $config['exposed_sort']['sort_order'];
  
          $exposed_sort = $sorts[$sort_by];
          $exposed_sort['order'] = $sort_order;

Additionally, I've noticed that if you take a VBO that has had an exposed sort and later turn it off, the placed VBOs will still sort. I'll suggest wrapping with:

    $filtered_allow = array_filter($this->getOption('allow'));
    $config = $block->getConfiguration();

    // If sort is configuration is turned off on the, do not allow overrides
    if (isset($filtered_allow['exposed_sort'])) { 
🐛 Bug report
Status

Fixed

Version

1.2

Component

Code

Created by

🇩🇪Germany Ken Hawkins

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024