function FacetapiWidgetLinks::buildListItems in Facet API 6.3
Same name and namespace in other branches
- 7.2 plugins/facetapi/widget_links.inc \FacetapiWidgetLinks::buildListItems()
- 7 plugins/facetapi/widget_links.inc \FacetapiWidgetLinks::buildListItems()
Recursive function that converts the render array into an array that can be passed to theme_item_list().
Parameters
array $build: The facet's render array.
Return value
array The "items" parameter for theme_item_list().
1 call to FacetapiWidgetLinks::buildListItems()
- FacetapiWidgetLinks::execute in plugins/
facetapi/ widget_links.inc - Renders the links.
File
- plugins/
facetapi/ widget_links.inc, line 69 - Widgets for facets rendered as links.
Class
- FacetapiWidgetLinks
- Widget that renders facets as a list of clickable links.
Code
function buildListItems($build) {
$settings = $this->settings->settings;
// Initializes links attributes, adds rel="nofollow" if configured.
$attributes = $settings['nofollow'] ? array(
'rel' => 'nofollow',
) : array();
$attributes += array(
'class' => $this
->getItemClasses(),
);
// Builds rows.
$items = array();
foreach ($build as $value => $item) {
$row = array(
'class' => array(),
);
// Initializes variables passed to theme hook.
$variables = array(
'text' => $item['#value'],
'path' => $item['#path'],
'count' => $item['#count'],
'options' => array(
'attributes' => $attributes,
'html' => $item['#html'],
'query' => $item['#query'],
),
);
// Adds the facetapi-zero-results class to items that have no results.
if (!$item['#count']) {
$variables['options']['attributes']['class'][] = 'facetapi-zero-results';
}
// Add an ID to identify this link.
$variables['options']['attributes']['id'] = _facetapi_html_id('facetapi-link');
// If the item has no children, it is a leaf.
if (empty($item['#item_children'])) {
$row['class'][] = 'leaf';
}
else {
// If the item is active or the "show_expanded" setting is selected,
// show this item as expanded so we see its children.
if ($item['#active'] || !empty($settings['show_expanded'])) {
$row['class'][] = 'expanded';
$row['children'] = $this
->buildListItems($item['#item_children']);
}
else {
$row['class'][] = 'collapsed';
}
}
// Gets theme hook, adds last minute classes.
$class = $item['#active'] ? 'facetapi-active' : 'facetapi-inactive';
$variables['options']['attributes']['class'][] = $class;
// Drupal 6 does not allow classes to be in an array
$variables['options']['attributes']['class'] = implode(' ', $variables['options']['attributes']['class']);
// Themes the link, adds row to items.
$row['data'] = theme($item['#theme'], $variables);
// Drupal 6 does not allow classes to be in an array
$row['class'] = implode(' ', $row['class']);
$items[] = $row;
}
return $items;
}