I am using OR facets with check boxes. Search API with Solr backend.

This is working great, but is there a way to have the clicked facets keep their count?

eg. for the facets field Colors i want the display to show something like:
[ ] White (10)
[  ] Blue (5)
[ ] Yellow (1)

If I check White, Blue stays at 5 and Yellow at 1, but the count after the active item is no longer shown.

I get this:
[X] White
[ ] Blue (5)
[ ] Yellow (1)

but would prefer this:

[X] White (10)
[ ] Blue (5)
[ ] Yellow (1)

I would like the only visual change with the facets block to be the check mark. :)

Atle

Comments

raphael apard’s picture

You can override theme function "theme_facetapi_link_active" :

function yourtheme_facetapi_link_active($variables) {

  // Sanitizes the link text if necessary.
  $sanitize = empty($variables['options']['html']);
  $link_text = ($sanitize) ? check_plain($variables['text']) : $variables['text'];


  // Adds count to link if one was passed.
  if (isset($variables['count'])) {
    $link_text .= ' ' . theme('facetapi_count', $variables);
  }


  // Theme function variables fro accessible markup.
  // @see node/1316580
  $accessible_vars = array(
    'text' => $variables['text'],
    'active' => TRUE,
  );

  // Builds link, passes through t() which gives us the ability to change the
  // position of the widget on a per-language basis.
  $replacements = array(
    '!facetapi_deactivate_widget' => theme('facetapi_deactivate_widget'),
    '!facetapi_accessible_markup' => theme('facetapi_accessible_markup', $accessible_vars),
  );
  $variables['text'] = t('!facetapi_deactivate_widget !facetapi_accessible_markup', $replacements);
  $variables['options']['html'] = TRUE;
  return theme_link($variables) . $link_text;
}

Just adding :

  // Adds count to link if one was passed.
  if (isset($variables['count'])) {
    $link_text .= ' ' . theme('facetapi_count', $variables);
  }
cpliakas’s picture

Category: feature » support
Status: Active » Fixed

Code looks good to me, and this seems like the correct approach.

Thanks for posting, wdki.
Chris

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.