Altering Drupal FacetAPI Counts and Active Links

Here is a quick snippet to alter Drupal FacetAPI counts and active links. Specifically what we wanted to do was make the whole active link clickable and give it an icon instead of the (-) text. We also needed to be able to style the FacetAPI count so we wrapped the count in a span and removed the parenthesis.

These functions will go into your template.php file. Don't forget to replace THEMENAME with the name of your theme. Both of these functions expect you to return the output you'd like to see printed on the page.


/*
 * Implements template_facetapi_count().
 *
 * Update the output of the facetapi count
 */
function THEMENAME_facetapi_count(&$vars) {
  // return a span that includes the count, without the parenthesis
  return '<span class="facet-count">' . (int) $vars['count'] . '</span>';
}

/*
 * Implements template_facetapi_link_active().
 *
 * Update the output of the facetapi active link
 */
function THEMENAME_facetapi_link_active(&$vars) {
  // return a link with our new structure.
  return l('<span class="glyphicon glyphicon-remove text-danger" aria-hidden="true"></span> ' . $vars['text'], $vars['path'], array('attributes' => $vars['options']['attributes'], 'html' => true));
}

Add new comment

Comments

Your function returns link with remove icon having path "products".
If we are having multiple filter (for ex: category, brand, size), consider we have selected 1 option from each (category,brand,size), Now if we go to remove brand (icon) the path is "product". It works as RESET button.

Plz have a solution