You are here

function FacetapiWidgetLinks::buildListItems in Facet API 7.2

Same name and namespace in other branches
  1. 6.3 plugins/facetapi/widget_links.inc \FacetapiWidgetLinks::buildListItems()
  2. 7 plugins/facetapi/widget_links.inc \FacetapiWidgetLinks::buildListItems()

Transforms the render array for use with theme_item_list().

The recursion allows this function to act on the various levels of a hierarchical data set.

Parameters

array $build: The items in the facet's render array being transformed.

Return value

array The "items" parameter for theme_item_list().

1 call to FacetapiWidgetLinks::buildListItems()
FacetapiWidgetLinks::execute in plugins/facetapi/widget_links.inc
Implements FacetapiWidget::execute().

File

plugins/facetapi/widget_links.inc, line 88
The facetapi_links and facetapi_checkbox_links widget plugin classes.

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(),
    );

    // Allow adding classes via altering.
    if (isset($item['#class'])) {
      $attributes['class'] = array_merge($attributes['class'], $item['#class']);
    }

    // Initializes variables passed to theme hook.
    $variables = array(
      'text' => $item['#markup'],
      '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'] = drupal_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;

    // Themes the link, adds row to items.
    $row['data'] = theme($item['#theme'], $variables);
    $items[] = $row;
  }
  return $items;
}