You are here

public function SearchApiGlossaryWidget::execute in Search API AZ Glossary 7.2

Same name and namespace in other branches
  1. 7.3 search_api_glossary.module \SearchApiGlossaryWidget::execute()

Renders the links.

File

./search_api_glossary.module, line 340
Search api glossary module file.

Class

SearchApiGlossaryWidget

Code

public function execute() {
  $element =& $this->build[$this->facet['field alias']];
  $total_count = 0;
  foreach ($element as &$e) {

    // Tally up the total hits for the "All" tab.
    $total_count += $e['#count'];
    if (isset($e['#active']) && $e['#active']) {
      $active = $e;
    }
    else {
      $e['#active'] = FALSE;
    }

    // For each link, drop any active facet that isn't defined by the
    // link itself. In effect, only the filter defined by the current
    // link is active.
    if (isset($e['#query']['f']) && is_array($e['#query']['f'])) {
      foreach ($e['#query']['f'] as $key => $value) {
        $temp = explode(':', $value);
        if ($temp[0] == $this->facet['field alias'] && $temp[1] != $e['#indexed_value']) {
          unset($e['#query']['f'][$key]);
        }
      }
    }
  }
  if ($this->settings->settings['show_all']) {

    // Create the "All" item using the last looped filter as the base.
    $all = isset($active) ? $active : $e;
    $all['#markup'] = t('All');
    $all['#count'] = $total_count;
    $all['#active'] = isset($active) ? FALSE : TRUE;
    $all['#path'] = isset($active) ? $all['#path'] : current_path();
    if (isset($all['#query']['f']) && is_array($all['#query']['f'])) {
      foreach ($all['#query']['f'] as $key => $value) {
        $temp = explode(':', $value);
        if ($temp[0] == $this->facet['field alias']) {
          unset($all['#query']['f'][$key]);
        }
      }
    }

    // Add our new tab to the beginning of the list.
    array_unshift($element, $all);
  }

  // Sets each item's theme hook, builds item list.
  $this
    ->setThemeHooks($element);
  $attributes = $this->build['#attributes'];
  $attributes['class'][] = 'tabs';
  $element = array(
    '#theme' => 'item_list',
    '#items' => $this
      ->buildListItems($element),
    '#attributes' => $attributes,
  );
}