5 * The standard url processor class.
9 * Url processor plugin that retrieves facet data from the query string.
11 * This plugin retrieves facet data from $_GET, and stored all information in
12 * the "f" query string variable by default.
14 class FacetapiUrlProcessorStandard
extends FacetapiUrlProcessor
{
17 * Implements FacetapiUrlProcessor::fetchParams().
19 * Use $_GET as the source for facet data.
21 public
function fetchParams() {
26 * Implements FacetapiUrlProcessor::normalizeParams().
28 * Strips the "q" and "page" variables from the params array.
30 public
function normalizeParams(array $params, $filter_key = 'f') {
31 return drupal_get_query_parameters($params, array('q', 'page'));
35 * Implements FacetapiUrlProcessor::getQueryString().
37 public
function getQueryString(array $facet, array $values, $active) {
38 $qstring = $this->params
;
39 $active_items = $this->adapter
->getActiveItems($facet);
41 // Appends to qstring if inactive, removes if active.
42 foreach ($values as
$value) {
43 if ($active && isset($active_items[$value])) {
44 unset($qstring[$this->filterKey
][$active_items[$value]['pos']]);
47 $field_alias = rawurlencode($facet['field alias']);
48 $qstring[$this->filterKey
][] = $field_alias .
':' .
$value;
52 // Removes duplicates, resets array keys and returns query string.
53 // @see http://drupal.org/node/1340528
54 $qstring[$this->filterKey
] = array_values(array_unique($qstring[$this->filterKey
]));
55 return array_filter($qstring);
59 * Implements FacetapiUrlProcessor::setBreadcrumb().
61 public
function setBreadcrumb() {
62 $breadcrumb = drupal_get_breadcrumb();
64 // Gets search keys and active items form the adapter.
65 $keys = $this->adapter
->getSearchKeys();
66 $active_items = $this->adapter
->getAllActiveItems();
68 $item = menu_get_item();
70 // Initializes base breadcrumb query.
71 $query = $this->params
;
72 unset($query[$this->filterKey
]);
74 // Adds the current search to the query.
76 // The last item should be text, not a link.
77 $breadcrumb[] = $active_items ?
l($keys, current_path(), array('query' => $query)) : check_plain($keys);
80 // Adds filters to the breadcrumb trail.
81 $last = end($active_items);
82 foreach ($active_items as
$item) {
83 $query[$this->filterKey
][] = rawurlencode($item['field alias']) .
':' .
$item['value'];
85 // Replaces with the mapped value.
86 $value = $this->adapter
->getMappedValue($item['facets'][0], $item['value']);
88 // The last item should be text, not a link.
90 $breadcrumb[] = !empty($value['#html']) ?
$value['#markup'] : check_plain($value['#markup']);
93 // Appends the filter to the breadcrumb trail.
94 $breadcrumb[] = l($value['#markup'], current_path(), array('query' => $query, 'html' => !empty($value['#html'])));
98 // Sets the breadcrumb trail with the keys and filters.
99 drupal_set_breadcrumb($breadcrumb);