Is it possible to combine the values of two taxonomy lists as filters

Created on 8 August 2019, over 5 years ago
Updated 17 April 2023, over 1 year ago

Is it possible to use a hook (or some other means) to merge the available items of a facet? Here is an example of what I mean:

We have a view which lists accommodation, and currently have the following facets set up to be able to filter the list:
-Amenities (uses amenities taxonomy)
-Star rating (uses star rating taxonomy)
-Town (uses town taxonomy)

We also have a 'City' taxonomy but it only currently contains 1 item, so instead of having another facet called 'City' with only one item, we want to merge the contents of the City and Town taxonomies which would show as filters under the Town facet. e.g.

| Town |
Town1 (4)
Town2 (1)
Town3 (8)
City1 (30)

Thanks,

Additional information:

We are using Apache Solr

So far I've used the hook facets_preprocess_facets_item_list(array &$variables) and after using kint on the variables array I see there is $variables['items'] which seems to hold the taxonomy filters to be used.
So I wonder if I can fetch an array similar to variables['items'] but using the City taxonomy instead of town, and then join these arrays and overwrite variables['items'] with the new array?

πŸ’¬ Support request
Status

Active

Version

1.4

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom cianevans

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

Comments & Activities

Not all content is available!

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

  • πŸ‡ΊπŸ‡ΈUnited States capellic Austin, Texas

    We need to do the same thing.

    In our situation we have two these two fields we need to combine:

    Primary Resource Type - Reference to Resource Types taxonomy vocabulary, single-value field
    Secondary Resource Types - Reference to Resource Types taxonomy vocabulary, multi-value field

    A given node might look like this:

    Primary Resource Type
    - Type 1

    Secondary Resource Types
    - Type 2
    - Type 3

    We want to provide a single facet to the user called "Resource Type"

    The node should appear if any of the terms (Type 1, Type 2, Type 3) are selected, regardless of the field.

    We've been experimenting with the Combine option on one of the facets, but it doesn't appear to work.

    @cianevans have you been able to resolve?

  • πŸ‡ΊπŸ‡ΈUnited States capellic Austin, Texas

    I'm wondering if this is related to https://www.drupal.org/project/facets/issues/3282290 πŸ› Combined facet active item incorrect Active

  • πŸ‡ΊπŸ‡ΈUnited States capellic Austin, Texas

    @DewinImagro

    No, no luck. And we tried the patch on https://www.drupal.org/project/facets/issues/3282290 πŸ› Combined facet active item incorrect Active without any luck either.

Production build 0.71.5 2024