5 * A taxonomy specific coder based on path aliases of terms.
7 * This handler reuses the path aliases of terms and hence avoids term ids in
8 * the facet URLs. It requires the default pattern for taxonomy terms
9 * ([term:vocabulary]/[term:name]), which can be configured at
10 * admin/config/search/path/patterns. The alias of [term:name] will be reused
11 * and combined with the facet alias ([facet:alias]/[term:name]).
15 * Taxonomy pathauto specific implementation of FacetApiPrettyPathsCoder.
17 class FacetApiPrettyPathsCoderTaxonomyPathauto
extends FacetApiPrettyPathsCoderDefault
{
20 * Taxonomy pathauto special case: <facet alias>/<term-name alias>
22 * @see FacetApiPrettyPathsCoderDefault::encodePathSegment()
24 public
function encodePathSegment(array $args) {
25 $voc_alias = $this->getVocabularyPathAlias($args['facet'], $args['adapter']);
27 if ($term = taxonomy_term_load($args['segment']['value'])) {
28 // Get the alias ([term:vocabulary]/[term:name]) for this term and
29 // extract the term:name part.
30 $alias = drupal_lookup_path('alias', 'taxonomy/term/' .
$term->tid
);
32 $parts = explode('/', $alias);
33 if (count($parts) == 2) {
34 $args['segment']['value'] = $parts[1];
39 return parent
::encodePathSegment($args);
43 * Taxonomy pathauto special case: <facet alias>/<term-name alias>
45 * @see FacetApiPrettyPathsCoderDefault::decodePathSegmentValue()
47 public
function decodePathSegmentValue(array $args) {
48 $voc_alias = $this->getVocabularyPathAlias($args['facet'], $args['adapter']);
50 // Rebuild the term alias, get the source (taxonomy/term/[term:tid]) and
51 // extract the term id.
52 $source = drupal_lookup_path('source', $voc_alias .
'/' .
$args['value']);
54 $exploded = explode('/', $source);
55 if (count($exploded) == 3) {
56 $args['value'] = $exploded[2];
60 return parent
::decodePathSegmentValue($args);
64 * Helper function that returns the path alias for a vocabulary.
66 private
function getVocabularyPathAlias($facet_info, $adapter) {
67 static
$aliases = array();
68 if (!isset($aliases[$facet_info['name']])) {
69 $aliases[$facet_info['name']] = FALSE
;
70 $facet_settings = $adapter->getFacetSettingsGlobal($facet_info);
71 $voc = taxonomy_vocabulary_machine_name_load($facet_settings->settings
['pretty_paths_taxonomy_pathauto_vocabulary']);
72 if ($voc && module_exists('pathauto')) {
73 // Needed, as of http://drupal.org/node/907578#comment-5564008
74 require_once
drupal_get_path('module', 'pathauto') .
'/pathauto.inc';
75 $aliases[$facet_info['name']] = pathauto_cleanstring($voc->name
);
78 return $aliases[$facet_info['name']];