public function CurrentSearchItemActive::execute in Facet API 6.3
Same name and namespace in other branches
- 7.2 contrib/current_search/plugins/current_search/item_active.inc \CurrentSearchItemActive::execute()
- 7 contrib/current_search/plugins/current_search/item_active.inc \CurrentSearchItemActive::execute()
Implements CurrentSearchItem::execute().
Overrides CurrentSearchItem::execute
File
- contrib/
current_search/ plugins/ current_search/ item_active.inc, line 16 - Displays all active items.
Class
- CurrentSearchItemActive
- Extension of CurrentSearchItem that displays all active items.
Code
public function execute(FacetapiAdapter $adapter) {
$items = array();
// Makes sure facet builds are initialized.
$adapter
->processFacets();
// Adds the keywords if any were passed.
$keys = $adapter
->getSearchKeys();
if ($this->settings['keys'] && $keys) {
$items[] = theme('current_search_keys', array(
'keys' => $keys,
'adapter' => $adapter,
));
}
// Initializes links attributes, adds rel="nofollow" if configured.
$attributes = $this->settings['nofollow'] ? array(
'rel' => 'nofollow',
) : array();
$attributes += array(
'class' => '',
);
// Gets the translated pattern with token replacements in tact.
$pattern = $this
->translate('pattern', $this->settings['pattern']);
// Adds active facets to the current search block.
foreach ($adapter
->getAllActiveItems() as $item) {
// Adds adapter to the active item for token replacement.
$item['adapter'] = $adapter;
// Builds variables to pass to theme function.
$variables = array(
'text' => token_replace($pattern, 'facetapi_active', $item),
'path' => $this
->getFacetPath($item, $adapter),
'options' => array(
'attributes' => $attributes,
'html' => TRUE,
'query' => $this
->getQueryString($item, $adapter),
),
);
// Renders the active link.
$items[] = theme('facetapi_link_active', $variables);
}
// If there are items, return the render array.
if ($items) {
$classes = $this->settings['css'] ? current_search_get_classes($this->settings['classes']) : '';
return array(
'#theme' => 'item_list',
'#items' => $items,
'#attributes' => array(
'class' => $classes,
),
);
}
}