Add replacement processor

Created on 19 July 2022, almost 3 years ago
Updated 10 July 2025, 8 days ago

Problem/Motivation

Howdy !

We need a mechanism to replace facet values.

One of our indexed fields contains language codes (i.e. en, fr). So, by default the facet looks like this:

What we want is to map the language codes with human readable values (i.e. English and French) so the facet looks like this:

Proposed resolution

Attached is a patch that adds a replacement processor. The processor maps raw values to display values using a mapping provided in the admin UI.

The admin UI looks like this (at /admin/config/search/facets/<my-facet>/edit):

Does this module already provide something equivalent ?

If not, does it make sense to incorporate this processor into https://drupal.org/project/facets ? Or should this be a separate contrib module (in which case we will promote this sandbox project as a full project: https://www.drupal.org/sandbox/fengtan/3298423 ).

Thanks !

Feature request
Status

Fixed

Version

2.0

Component

Code

Created by

🇨🇦Canada fengtan Montreal, Canada

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.

  • 🇨🇦Canada jinah2020

    Adding translation support for replacement values
    This patch wraps the replacement values with the $this->t() function to enable translation of the mapped display values.
    Changes made:

    Modified the replacement processor to translate the $new_value using $this->t($new_value)
    This allows the human-readable replacement strings (like "English", "French") to be translated into other languages
    The mapping keys (original values like "en", "fr") remain untranslated as expected

Production build 0.71.5 2024