I am using the checkboxes in my facets and would like to hide the facet counts that show up, how can this be achieved?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cpliakas’s picture

Hi BeaPower.

You can do this via theme hook overrides. See #1396348: Option to remove the link count satisfying a different use case, but using the same technique you will need to no show the facet counts.

Thanks,
Chris

cpliakas’s picture

Status: Active » Fixed

Marking as fixed after weeks of inactivity.

Status: Fixed » Closed (fixed)

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

nedjo’s picture

Issue tags: +FAQ

#1615430: How to hide facet counts? was closed as a duplicate.

You can achieve this in a preprocess function:

/*
 * Implements template_preprocess_facetapi_link_inactive().
 *
 * Remove the count from Facet links.
 */
function mytheme_preprocess_facetapi_link_inactive(&$variables) {
  unset($variables['count']);
}
kopeboy’s picture

Component: Documentation » User interface
Category: Support request » Feature request
Issue summary: View changes
Status: Closed (fixed) » Active

I think it's incredible we don't have a checkbox in the configuration UI to disable this for a particular search filter.

This is basic stuff imho, when you have thousands of results, especially if the filter is the primary one (having multiple dependent filters), you usually don't want to show the number.

I don't have the skills to do this with php, if the feature won't come, can anyone provide some instructions to hide the facet count for a particular filter with the php snippet noted above?

Thanks

kitikonti’s picture

Because i also need this feature i tried to create a patch so we you enable or disable the count from the ui. But i have a problem with the checkbox. I created a new checkbox in the settingsForm() function which looks like:

    $form['widget']['widget_settings']['links'][$this->id]['show_count'] = array(
      '#type' => 'checkbox',
      '#title' => t('Show count'),
      '#default_value' => !empty($this->settings->settings['show_count']),
      '#description' => t('Show the facet count.'),
      '#states' => array(
        'visible' => array(
          'select[name="widget"]' => array('value' => $this->id),
        ),
      ),
    );

I have set the default value to 1 in the getDefaultSettings() function. But the checkbox dont work, it keeps always 1. Could anyone tell me whats the problem with this, so i could submit a patch?

kitikonti’s picture

Version: 7.x-2.x-dev » 7.x-1.x-dev
Status: Active » Needs review
Issue tags: -FAQ
FileSize
2.87 KB

So after a few hours i figured it out, there happens some javascript magic in the form. I have a patch created for the 7.x-1.x-dev (also works in 7.x-1.5) which adds a checkbox in the display settings form, which by default is checked to show the count. I have not looked at the 7.x-2.x versions if it is also possible there because me is using the current recommended verison which is 7.x-1.5.

KelvinWong’s picture

Great work kitikonti, #7 works. Would you able to make it compatible with search_api_ranges?

Many thanks

kitikonti’s picture

maybe because i am also using it, but i dont know when i have time for it

ssoulless’s picture

Priority: Normal » Minor
Status: Needs review » Reviewed & tested by the community

#7 should ber committed, Im working with it in a production site 1 month ago. and it works like a charm maybe the search_api_ranges compatibility can be another thread after this is commited

kitikonti’s picture

i also think this should do it for now. for compatibility to search_api_ranges i think the most work has to be done in it's widget functions so this should be an extra issue for search_api_ranges anyway.

vegardjo’s picture

I did this in a theme function in my themes template.php file:

<?php
function mytheme_facetapi_count($variables) {
  return '<span class="counter">(' . (int) $variables['count'] . ')</span>';
}
?>

..so basically wrapping the count in a span, and then hide or change it with CSS

thierrydallacroce’s picture

#4 is a solution, at least until the patch is applied to 1.x.
However for clarification, the comment should reflect that it implements a hook_preprocess_HOOK for theme_facetapi_link_inactive().

cmseasy’s picture

Patch 7 is working, I agry with #10

Scott Robertson’s picture

Status: Reviewed & tested by the community » Closed (duplicate)

This patch did not work for me when I applied it to the latest version of 1.x. However, the patch here works:

https://www.drupal.org/node/2194423#comment-9779337

Marking this as a duplicate of #2194423

Scott Robertson’s picture