Facets Pretty Paths

Provides clean, SEO-friendly URL paths for Facets module by converting query string parameters into human-readable path segments.

facets_pretty_paths
6,836 sites
62
drupal.org

インストール

Drupal 11, 10, 9 v2.0.4
composer require 'drupal/facets_pretty_paths:^2.0'

概要

Facets Pretty Pathsは、Facetsモジュールが生成するデフォルトのファセットURLを、クエリ文字列ベースのパラメータ(例:/search?f[0]=color:blue)からクリーンで読みやすいパスセグメント(例:/search/color/blue)に変換します。このアプローチにより、より直感的で共有しやすいURLが作成され、SEOパフォーマンスとユーザーエクスペリエンスの両方が向上します。

このモジュールは、ファセット値をURLにエンコードする方法と、元の値にデコードする方法を決定するプラグイン可能な「Coder」システムを提供します。これにより、フィルタリングされるデータの種類(タクソノミーターム、リストアイテム、ノード参照など)に応じて、異なるエンコーディング戦略を使用できます。複数の組み込みCoderが提供されており、Coderプラグインインターフェースを実装することでカスタムCoderを作成することもできます。

ファセットソースで有効にすると、モジュールはソースのルートを動的に変更して、ファセットフィルターをパスセグメントとして受け入れます。また、フィルタリングされた検索結果ページのパンくずリストを自動生成する機能も提供します。

Features

  • クエリ文字列パラメータの代わりにクリーンなパスセグメントを生成するURL Processorプラグイン(例:/brand/drupal/color/blue)
  • URL内のファセット値をエンコード・デコードするためのプラグイン可能なCoderシステム - ファセットごとにカスタム変換ロジックを設定可能
  • 変換なしで生の値を使用する組み込みDefault Coder(例:/color/2)
  • 一意性のためにターム名とIDを使用する組み込みTaxonomy Term Coder(例:/color/blue-2)
  • よりクリーンなURLのためにターム名のみを使用する組み込みTaxonomy Term Name Coder(例:/color/blue)
  • ラベルとIDを使用するオプションリストフィールド用の組み込みList Item Coder(例:/status/published-1)
  • ノードタイトルとIDを使用するエンティティ参照フィールド用の組み込みNode Title Coder(例:/author/john-smith-42)
  • ファセットソースルートでfacets_queryパラメータを受け入れるための自動ルート変更
  • URLパスセグメントを解析して現在アクティブなファセット選択を判定するアクティブフィルターサービス
  • 適切なナビゲーションリンクを持つファセット検索ページ用のカスタムパンくずリストビルダー
  • 親子関係の処理を含む階層ファセットのサポート
  • 適切なURLコンテキスト保持によるViewsのAJAXサポート
  • ファセットコンテキストを含むViews Data Exportのバッチ処理サポート

Use Cases

SEO-Optimized E-commerce Filtering

An online store uses Facets Pretty Paths to create clean, indexable URLs for product filters. Instead of /products?f[0]=category:shoes&f[1]=color:blue, customers see /products/category/shoes/color/blue. This improves search engine indexing and allows users to bookmark and share specific filtered views.

Multilingual Taxonomy Filtering

A multilingual site uses the Taxonomy Term Name Coder to display facet values in the user's language. When filtering by category 'Electronics' in English, the URL shows /search/category/electronics, while the same filter in German shows /search/kategorie/elektronik, improving local SEO.

Content Type Filtering

A news portal allows filtering articles by type using a list field. With the List Item Coder, the URL /news/type/opinion-3 clearly indicates the filter while maintaining the internal value reference for reliable decoding.

Author-Based Content Filtering

A blog uses entity reference fields to link content to author profiles. The Node Title Coder creates URLs like /articles/author/jane-doe-15 that are both human-readable and uniquely identifiable.

Custom Coder Implementation

A site with complex facet value requirements implements a custom coder plugin. By implementing CoderInterface with encode() and decode() methods, developers can create site-specific URL encoding logic, such as using SKUs for product variants or custom slugs for categories.

Tips

  • Set the facet 'URL alias' to a short, descriptive name as this becomes part of the URL path (e.g., 'brand' instead of 'field_product_brand')
  • Use the Taxonomy Term Name Coder only when term names are guaranteed unique within the vocabulary to avoid ambiguous decoding
  • Consider facet weight settings as they affect the order of path segments in URLs - consistent ordering helps with caching and SEO
  • Custom coders can be created by implementing CoderInterface - define encode() for URL generation and decode() for parsing
  • The breadcrumb builder has priority 1500, which can be adjusted if conflicts occur with other breadcrumb modules
  • When debugging, check the 'facets_query' route parameter to see the raw filter string being parsed

Technical Details

Admin Pages 2
Facet Source Configuration /admin/config/search/facets/facet-sources/{facet_source_id}/edit

Configure the URL handler for a facet source. Select 'Pretty paths' to enable clean URL paths for all facets using this source instead of query string parameters.

Facet Configuration /admin/config/search/facets/{facets_facet}/edit

When Pretty Paths is enabled for the facet source, an additional 'Pretty paths coder' setting appears in the Facet settings section allowing you to select how this specific facet's values are encoded in URLs.

Hooks 1
hook_form_facets_facet_edit_form_alter

Alters the facet edit form to add the Pretty Paths coder selection when Pretty Paths is enabled for the facet source.

Troubleshooting 6
Facet URLs still show query string parameters after enabling Pretty Paths

Ensure you have selected 'Pretty paths' as the URL handler in the facet source configuration, not just the individual facet. After changing the setting, clear all caches to rebuild routes.

Facet links return 404 errors

The route may not have been rebuilt. Clear caches with 'drush cr' or via /admin/config/development/performance. Also verify that the base path exists and the facet source is correctly configured.

Taxonomy term facets show IDs instead of names

Change the Pretty Paths coder setting on the facet from 'Default' to 'Taxonomy term name + id' or 'Taxonomy term name' depending on your preference.

Active filters not recognized after AJAX refresh

This was addressed in issue #3129632. Update to the latest version of the module. The fix ensures facet context is extracted from AJAX request parameters and referer headers.

URL path becomes too long with many active filters

Due to database limitations, the router table has a 255 character path limit. The module adds placeholder parameters to work around core routing issues, but extremely long filter combinations may still exceed limits. Consider reducing the number of simultaneously active facets.

Taxonomy Term Name Coder returns wrong term

The name-only coder searches all terms in configured vocabularies. If multiple terms have the same name, it returns the first match. Use 'Taxonomy term name + id' coder for guaranteed uniqueness.

Security Notes 3
  • Facet values in URLs are sanitized using Pathauto's alias cleaner, which applies transliteration and removes unsafe characters
  • The module uses access checking when loading entities during encoding/decoding operations
  • Input from URL path segments is properly validated against existing facet configurations before processing