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'])) {
Issue fork views_block_override-3324372
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
Comment #3
dubois commentedNot 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
Comment #4
dubois commentedComment #5
tim-dielsI 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.
Comment #6
tim-dielsI'm not seeing any problem in adding this to the codebase. So I'm going to update the MR.
Comment #7
tim-dielsUpdated the MR. Could you please check if that works for you also?
Comment #8
ken hawkins commentedThanks for this. We'll test this next week and update.
Comment #9
tim-dielsGreat, looking forward for the feedback.
Comment #10
tim-dielsLets target this for 1.2.x
Comment #14
tim-dielsAdded this to the 1.2.x branch.