Problem/Motivation

I was testing the facet summary block when I found that facet weight is ignored.

By the way: amazing work on the facet summary block!

See attached screenshots. Facets order is "Besoin" then "Domaine" but in the summary it is "Domaine" then "Besoin".

Switching the facets order changes nothing in front.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork facets-3251920

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

Grimreaper created an issue. See original summary.

marcvangend’s picture

Issue tags: +Needs tests

I see the same. The cause of the problem seems to be that \Drupal\facets_summary\FacetsSummaryManager\DefaultFacetsSummaryManager::build has the correct order available in $facets_config, but instead of looping over that, it iterates over the unordered $facets to build the output. This could be solved by ordering $facets by the keys of $facets_config like this:

    $order = array_keys($facets_config);
    $facets = array_replace(array_flip($order), $facets);

But I think that's not all. While this seems to work correctly for the "reset_facets" summary processor, I noticed that \Drupal\facets_summary\Plugin\facets_summary\processor\ShowSummaryProcessor::build uses array_unshift to add the items to an array. So that suggests that the order would still be reversed. I hope this helps someone get started with a proper issue fork or patch.

Also, needs tests.

nmillin made their first commit to this issue’s fork.

nmillin’s picture

I followed what @marcvangend did, and it worked for me. I created the fork/MR to get something started. There will need to be tests (like what marcvangend mentioned).

Hopefully this will help others review this. Thanks.

gnuget made their first commit to this issue’s fork.

gnuget’s picture

Status: Active » Needs review
Issue tags: -Needs tests

I added the tests and adjusted a bit the method used to order the facet summary (instead of relying on the configuration, the `#weight` is checked).

The same tests that fail on the dev version of the module are failing here so the new tests are passing 🥳

This is ready to be reviewed.

Thanks, @Grimreaper and @nmillin for the initial work.

(I created two more branches by accident lol, I'm still learning how to use gitlab instead of relying on patches, apologies for that 😅)

gnuget’s picture

I just realized that relying on the patch generated by the merge request might not be best idea given that if it is updated the Merge Request the patch will be updated, so here a static version of the patch.

andreasderijcke’s picture

Version: 2.0.0-rc1 » 2.0.7

Patch from #8 still works on 2.0.7 and fixes the issue for us.

  • borisson_ committed 6ac43b2c on 3.0.x
    Issue #3251920 by gnuget, nmillin, Grimreaper, marcvangend, borisson_:...

  • borisson_ committed 0068ab91 on 2.0.x
    Issue #3251920 by gnuget, nmillin, Grimreaper, marcvangend, borisson_:...
borisson_’s picture

Status: Needs review » Fixed

Looks great, thanks all.

Status: Fixed » Closed (fixed)

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