Add processor to show parents in hierarchical facets

Created on 21 September 2023, almost 2 years ago

Problem/Motivation

I want to show parents of an facet item even if there is no results by parent. In this way I want to keep hierarchy same to defined for vocabulary. (By the way, should it be a native behavior of an hierarchy facet?)

There is "

Steps to reproduce

if there is no content assigned to "Parent" term, "Child" term is displayed as root in the hierarchical facet.

Proposed resolution

Add a ShowParentsProcessor

Remaining tasks

Write tests

User interface changes

New option in processors list

API changes

None, HierarchyInterface::getParentIds() already exists

Data model changes

None

✨ Feature request
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡§πŸ‡ΎBelarus dewalt

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

Merge Requests

Comments & Activities

  • Issue created by @dewalt
  • Status changed to Needs review almost 2 years ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update almost 2 years ago
    424 pass, 2 fail
  • Status changed to Needs work 3 months ago
  • πŸ‡§πŸ‡·Brazil andre.bonon

    I tested the patch on Facets 3.0, and it worked, but I had to make some changes. I had to implement the supportsFacet() method to work properly with facets_exposed_filters.
    I’ll create a fork soon.

  • Pipeline finished with Canceled
    3 months ago
    Total: 339s
    #485118
  • πŸ‡§πŸ‡·Brazil andre.bonon

    I assumed this new processor should only work with taxonomy terms, so I added the same check used in TermWeightWidgetOrderProcessor. To avoid duplicating code, I encapsulated the logic into a trait and updated that class to use it as well.

  • πŸ‡§πŸ‡·Brazil andre.bonon

    This is how it is rendered in filter settings.

  • Pipeline finished with Failed
    3 months ago
    Total: 1871s
    #485121
  • Pipeline finished with Running
    3 months ago
    #485868
  • πŸ‡ΊπŸ‡ΈUnited States damienmckenna NH, USA

    IMHO this is a bug report, and when enabled is the expected behavior.

    I've been pulling my hair out over this, trying to work out why the term hierarchy is not shown, only for it to be a problem with the module.

    Thank you for this fix!

  • πŸ‡ΊπŸ‡ΈUnited States damienmckenna NH, USA

    This works great, once you set the processors to the correct order, e.g.:
    * Show parents
    * URL handler
    * Transform entity ID to label
    * Build hierarchy tree

    Marking RTBC to get the maintainer to take a look.

  • πŸ‡ΊπŸ‡ΈUnited States damienmckenna NH, USA

    On a local barebones 11.1.x install with the latest Facets 3.0.x I could not reproduce the problem that this resolves.

    We might need to dig into it a little more and add test coverage to confirm exactly what behavior we're after, because I wonder how much of it is a data problem?

  • πŸ‡ΊπŸ‡ΈUnited States damienmckenna NH, USA

    On a website I'm using this with I'm seeing some unexpected behavior where terms are being placed under incorrect parent items. For example, I have one term which does not have a parent in the database, but it is placed under a term which isn't even in the vocabulary that the first term comes from.

  • Status changed to Needs review about 1 month ago
  • πŸ‡§πŸ‡·Brazil andre.bonon

    I set up a new sandbox and was able to identify what was missing in the original one.
    It turns out the Index hierarchy processor wasn’t enabled on the site where I encountered the issue.

    I'm not sure if the ShowParents processor is still needed.

  • Pipeline finished with Canceled
    about 1 month ago
    Total: 112s
    #538317
  • Pipeline finished with Success
    about 1 month ago
    Total: 890s
    #538319
Production build 0.71.5 2024