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'])) { 
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Ken Hawkins created an issue. See original summary.

dubois’s picture

Not sure the problem is in this module. The ViewsBlockOverride::blockSubmit function is not called when block form is submitted via Gutenberg. The way the settings form is rendered in Gutenberg's BlockSettingsForm doesn't pick up the blockSubmit function from the class.

Created a support request on Gutenberg queue: https://www.drupal.org/project/gutenberg/issues/3350187

dubois’s picture

tim-diels’s picture

Status: Needs review » Postponed (maintainer needs more info)

I had to change the module code a bit to fix other issues. I guess the problem should be fixed as I've altered the data structure to be like what you suggest.

tim-diels’s picture

Status: Postponed (maintainer needs more info) » Active

I'm not seeing any problem in adding this to the codebase. So I'm going to update the MR.

tim-diels’s picture

Status: Active » Needs review

Updated the MR. Could you please check if that works for you also?

ken hawkins’s picture

Thanks for this. We'll test this next week and update.

tim-diels’s picture

Great, looking forward for the feedback.

tim-diels’s picture

Version: 1.0.x-dev » 1.2.x-dev

Lets target this for 1.2.x

tim-diels changed the visibility of the branch 1.2.x to hidden.

  • tim-diels committed 755fd20f on 1.2.x
    Issue #3324372 by tim-diels, Ken Hawkins, dubois: Adapt exposed sorts...
tim-diels’s picture

Status: Needs review » Fixed

Added this to the 1.2.x branch.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.