You are here

public function FacetapiUrlProcessorStandard::setBreadcrumb in Facet API 6.3

Same name and namespace in other branches
  1. 7.2 plugins/facetapi/url_processor_standard.inc \FacetapiUrlProcessorStandard::setBreadcrumb()
  2. 7 plugins/facetapi/url_processor_standard.inc \FacetapiUrlProcessorStandard::setBreadcrumb()

Implements FacetapiUrlProcessor::setBreadcrumb().

Overrides FacetapiUrlProcessor::setBreadcrumb

File

plugins/facetapi/url_processor_standard.inc, line 89
The standard URL processor.

Class

FacetapiUrlProcessorStandard
Extension of FacetapiUrlProcessor.

Code

public function setBreadcrumb() {
  $breadcrumb = drupal_get_breadcrumb();

  // Gets search keys and active items form the adapter.
  $keys = $this->adapter
    ->getSearchKeys();
  $active_items = $this->adapter
    ->getAllActiveItems();
  $item = menu_get_item();
  $last_load_func = is_array($item['load_functions']) ? end($item['load_functions']) : NULL;
  if (!empty($item['title']) && (!$keys && $active_items || $keys && $last_load_func != 'menu_tail_load')) {
    $last = end($breadcrumb);
    $this_page = l($item['title'], $item['href'], $item['localized_options']);
    if ($last != $this_page) {
      $breadcrumb[] = $this_page;
    }
  }

  // Initializes base breadcrumb query.
  $query = $this->params;
  unset($query[$this->filterKey]);

  // Adds the current search to the query.
  if ($keys) {

    // The last item should be text, not a link.
    $breadcrumb[] = $active_items ? l($keys, $_GET['q'], array(
      'query' => $query,
    )) : check_plain($keys);
  }

  // Adds filters to the breadcrumb trail.
  $last = end($active_items);
  foreach ($active_items as $item) {
    $query[$this->filterKey][] = rawurlencode($item['field alias']) . ':' . $item['value'];

    // Replaces with the mapped value.
    $value = $this->adapter
      ->getMappedValue($item['facets'][0], $item['value']);

    // The last item should be text, not a link.
    if ($last == $item) {
      $breadcrumb[] = !empty($value['#html']) ? $value['#value'] : check_plain($value['#value']);
    }
    else {

      // Appends the filter to the breadcrumb trail.
      $breadcrumb[] = l($value['#value'], $_GET['q'], array(
        'query' => $query,
        'html' => !empty($value['#html']),
      ));
    }
  }

  // Sets the breadcrumb trail with h keys and filters.
  drupal_set_breadcrumb($breadcrumb);
}