summaryrefslogtreecommitdiffstats
path: root/plugins/coders/facetapi_pretty_paths_coder_taxonomy.inc
blob: c2aa454b253face570b2456830eaf9b8a4eddf0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php

/**
 * @file
 * A taxonomy specific coder for pretty paths.
 */

/**
 * Taxonomy specific implementation of FacetApiPrettyPathsCoder.
 */
class FacetApiPrettyPathsCoderTaxonomy extends FacetApiPrettyPathsCoderDefault {

  /**
   * Taxonomy special case: <alias>/<term-name>-<term-id>
   *
   * @see FacetApiPrettyPathsCoderDefault::encodePathSegment()
   */
  public function encodePathSegment(array $args) {
    if ($term = taxonomy_term_load($args['segment']['value'])) {
      $args['segment']['value'] = $this->prettyPath($term->name) . '-' . $term->tid;
    }
    return parent::encodePathSegment($args);
  }

  /**
   * Taxonomy special case: <alias>/<term-name>-<term-id>
   *
   * @see FacetApiPrettyPathsCoderDefault::decodePathSegmentValue()
   */
  public function decodePathSegmentValue(array $args) {
    $exploded = explode('-', $args['value']);
    $args['value'] = array_pop($exploded);
    return parent::decodePathSegmentValue($args);
  }
}