Entity Reference Facet Link
Provides field formatters for entity reference fields that link referenced entities to faceted search pages instead of their default view pages.
entity_reference_facet_link
Install
composer require 'drupal/entity_reference_facet_link:^2.0'
Overview
Entity Reference Facet Link provides specialized field formatter plugins for entity reference fields, including taxonomy term reference fields. These formatters transform entity reference field displays into links that point to a faceted search page filtered by the referenced entity, rather than linking to the entity's default view page.
This module solves a common usability problem in Drupal sites with faceted search functionality. When you have a faceted search page (created using Views, Search API, and the Facets module) that filters content by taxonomy terms, clicking on a taxonomy term displayed on a node would typically take you to that term's default view page. However, users often expect to be taken back to the search page filtered by that term. This module provides exactly that functionality.
The module automatically handles URL generation using the same URL processor configured for your facets, meaning it works seamlessly with modules like Facets Pretty Paths. Simply select a facet from the formatter settings, and the module handles all the URL formatting automatically.
Features
- Provides a 'Facet link' field formatter that displays entity reference labels as clickable links to faceted search pages
- Provides a 'Facet URL' field formatter that displays just the raw URL of the faceted search page
- Automatically filters selectable facets to only show those that match the field being configured
- Supports all URL processors used by the Facets module, including Facets Pretty Paths
- Properly handles cache invalidation when referenced entities or facet configurations change
- Works with any entity reference field type, including taxonomy term reference fields
Use Cases
Taxonomy term links on article pages
You have a blog with articles tagged with taxonomy terms (e.g., categories or topics). You have a faceted search page that allows filtering articles by these terms. Instead of taxonomy term links on articles going to the term's default taxonomy page, you want them to link to your faceted search page with that term pre-selected. Configure the taxonomy term field display to use 'Facet link' and select your search page's facet.
Author links to filtered content lists
Your site has an author entity reference field on content. You have a faceted search page with an author facet. Using this module, author names on content can link directly to the search page filtered by that author, showing all content by that author.
Product category navigation in e-commerce
In a Drupal Commerce site with a faceted product search, product category references on product pages can link back to the search page filtered by that category, providing a seamless browsing experience.
Content type filtered views
You have multiple content types that reference shared entities. Using this module, those entity references can link to a faceted search page filtered appropriately, allowing users to discover related content easily.
Tips
- Give your facets unique, descriptive names so you can easily identify them in the formatter settings, especially if you have the same field used as a facet on multiple search pages.
- The module automatically handles cache tags, so links will update when the referenced entity's label changes or when the facet configuration is modified.
- You can use the 'Facet URL' formatter if you need just the URL for custom theming or JavaScript purposes.
Technical Details
Troubleshooting 3
Ensure you have created facets in the Facets module that are configured for the same field you are trying to format. The module only shows facets that match the current field.
Clear your site's cache manually. There is currently no way to automatically invalidate the field's display cache when the source path is updated.
The module uses the same URL processor configured for your facet. Verify that your facet is using the correct URL processor in its configuration.