Taxonomy Results

Enhances Vactory project with a Term result count custom entity.


Introduction

The main utility of the taxonomy results module is to track the frequency of term usage within the desired entity.

Concrete Example : For instance, it allows us to display exclusively those terms that have been used in the listing filters.

Installation

  1. Enable the module with the following drush command : drush en vactory_taxonomy_results -y

  2. Visit : /admin/config/system/taxonomy-results-count

You need to enable for each entity type the concerned bundle that results count should be calculated for related taxonomy term entity reference fields (whenever exists).

Then you need to check Calculate taxonomy term results after saving configuration checkbox to start counting each term results process after saving configuration

Then try to access results count entity list through /admin/content/term-result-count

Custom Plugin TermResultCountManager

The module by default provide a default term result count plugin, you could add you're own calculation, by creating a new plugin, the plugin class should be defined in my_module/src/Plugin/TermResultCounter and implements the method termResultCount.

See example on: vactory_taxonomy_results/src/Plugin/TermResultCounter/DefaultTermResultCounter.php

Client Side

./apps/starter/components/modules/news/NewsListWidget.jsx

const NewsListWidget = ({ data }) => {
console.log({data})
return <>News listing</>
}

Visit the news listing page to see the taxonomies object :

We observe the addition of a new property results to the term object, providing us with additional information regarding the frequency of this term's usage within the relevant entity, which, in our case, pertains to the node entity, vactory_news bundle.

⚠️
We can see that the results object is an array of objects. This arrangement allows us to calculate terms using various plugins, including custom ones. Each object in the array indicates which plugin was used for term calculation.