5 * Base url processor plugin class.
9 * Abstract class extended by url processor plugins.
11 * Url processor plugins provide a pluggable method of retrieving facet data.
12 * Most commonly facet data is retrieved from a query string variable via $_GET,
13 * however custom plugis can be written to retrieve data from the path as well.
14 * In addition to facet data retrieval, the url processor plugin is also
15 * responsible for building facet links and setting breadcrumb trails.
17 * Each adapter instance is associated with a single url processor plugin. The
18 * plugin is associated with the adapter via hook_facetapi_searcher_info()
21 abstract
class FacetapiUrlProcessor
{
24 * The adapter that the url processor plugin is associated with.
26 * @var FacetapiAdapter
31 * An array of facet params, usually $_GET.
35 protected
$params = array();
38 * The array key in FacetapiUrlProcessor::params containing the facet data.
42 protected
$filterKey = 'f';
45 * Constructs a FacetapiUrlProcessor object.
47 * @param FacetapiAdapter $adapter
48 * The adapter that the url processor plugin is associated with.
50 public
function __construct(FacetapiAdapter
$adapter) {
51 $this->adapter
= $adapter;
55 * Fetches parameters from the source, usually $_GET.
57 * This method is invoked in FacetapiAdapter::__construct().
60 * An associative array containing the params, usually $_GET.
62 abstract public
function fetchParams();
65 * Normalizes the array returned by FacetapiAdapter::fetchParams().
67 * When extracting data from a source such as $_GET, there are certain items
68 * that you might nor want, for example the "q" or "page" keys. This method is
69 * useful for filtering those out. In addition, plugins that do not get data
70 * from $_GET can use this method to normalize the data into an associative
71 * array that closely matches the data structure of $_GET.
73 * @param array $params
74 * An array of keyed params, usually as $_GET.
75 * @param string $filter_key
76 * The array key in $params containing the facet data, defaults to "f".
79 * An associative array containing the normalized params.
81 abstract public
function normalizeParams(array $params, $filter_key = 'f');
84 * Returns the query string variables for a facet item.
86 * The return array must be able to be passed as the "query" key of the
87 * options array passed as the second argument to the url() function. See
88 * http://api.drupal.org/api/drupal/includes%21common.inc/function/url/7 for
92 * The facet definition as returned by facetapi_facet_load().
93 * @param array $values
94 * An array containing the item's values being added to or removed from the
95 * query string dependent on whether or not the item is active.
97 * An integer flagging whether the item is active or not. 1 if the item is
98 * active, 0 if it is not.
101 * The query string variables.
103 abstract public
function getQueryString(array $facet, array $values, $active);
106 * Returns the path for a facet item.
108 * @param array $facet
109 * The facet definition.
110 * @param array $values
111 * An array containing the item's values being added to or removed from the
112 * query string dependent on whether or not the item is active.
114 * An integer flagging whether the item is active or not.
117 * The path of the facet.
119 public
function getFacetPath(array $facet, array $values, $active) {
120 return $this->adapter
->getSearchPath();
124 * Sets the breadcrumb trail for active searches.
126 * This method is called by FacetapiAdapter::processFacets(), which is called
127 * directly by the backend to search the chain of Facet API events.
129 abstract public
function setBreadcrumb();
132 * Sets the normalized parameters.
134 * This method is usually called by FacetapiAdapter::setParams() and is very
135 * rarely called directly.
137 * @param array $params
138 * An array of normalized params hat have already been passed through
139 * FacetapiUrlProcessor::normalizeParams().
140 * @param string $filter_key
141 * The array key in $params containing the facet data, defaults to "f".
143 * @return FacetapiUrlParser
144 * An instance of this class.
146 public
function setParams(array $params, $filter_key = 'f') {
147 $this->params
= $params;
148 $this->filterKey
= $filter_key;
149 if (!isset($this->params
[$this->filterKey
]) || !is_array($this->params
[$this->filterKey
])) {
150 $this->params
[$this->filterKey
] = array();
156 * Returns the params.
159 * An array containing the params.
161 public
function getParams() {
162 return $this->params
;
166 * Removes an item from the $this->params array.
169 * The zero-based position of the value in the source data.
171 public
function removeParam($pos) {
172 unset($this->params
[$this->filterKey
][$pos]);
176 * Returns the filter key.
179 * A string containing the filter key.
181 public
function getFilterKey() {
182 return $this->filterKey
;