function FacetapiAdapter::addActiveFilters in Facet API 7.2
Same name and namespace in other branches
- 6.3 plugins/facetapi/adapter.inc \FacetapiAdapter::addActiveFilters()
- 7 plugins/facetapi/adapter.inc \FacetapiAdapter::addActiveFilters()
Allows the backend to add facet queries to its native query object.
This method is called by the implementing module to initialize the facet display process. The following actions are taken:
- FacetapiAdapter::initActiveFilters() hook is invoked.
- Dependency plugins are instantiated and executed.
- Query type plugins are executed.
@todo Should this method be deprecated in favor of one name init()? This might make the code more readable in implementing modules.
Parameters
mixed $query: The backend's native query object.
See also
FacetapiAdapter::initActiveFilters()
File
- plugins/
facetapi/ adapter.inc, line 658 - Adapter plugin and adapter related classes.
Class
- FacetapiAdapter
- Abstract class extended by Facet API adapters.
Code
function addActiveFilters($query) {
module_load_include('inc', 'facetapi', 'facetapi.callbacks');
facetapi_add_active_searcher($this->info['name']);
// Invoke initActiveFilters hook.
$this
->initActiveFilters($query);
foreach ($this
->getEnabledFacets() as $facet) {
$settings = $this
->getFacet($facet)
->getSettings();
// Instantiate and execute dependency plugins.
$display = TRUE;
foreach ($facet['dependency plugins'] as $id) {
$class = ctools_plugin_load_class('facetapi', 'dependencies', $id, 'handler');
$plugin = new $class($id, $this, $facet, $settings, $this->activeItems['facet']);
if (NULL !== ($return = $plugin
->execute())) {
$display = $return;
}
}
// Store whether this facet passed its dependencies.
$this->dependenciesPassed[$facet['name']] = $display;
// Execute query type plugin if dependencies were met, otherwise remove
// the facet's active items so they don't display in the current search
// block or appear as active in the breadcrumb trail.
if ($display && $this->queryTypes[$facet['name']]) {
$this->queryTypes[$facet['name']]
->execute($query);
}
else {
foreach ($this->activeItems['facet'][$facet['name']] as $item) {
$this->urlProcessor
->removeParam($item['pos']);
$filter = $item['field alias'] . ':' . $item['value'];
unset($this->activeItems['filter'][$filter]);
}
$this->activeItems['facet'][$facet['name']] = array();
}
}
}