Normally with facetapi facets you can theme the facets, for example to change the way the count is displayed in relation to the facet text.

This is currently not possible as options are just set to $item['#markup'].' ('.$item['#count'].')';

Also, when #2118323: Add default option when facet is active is committed possibly people will want to theme active facets differently to inactive ones.

Comments

rooby’s picture

PCateNumbersUSA’s picture

Would love this as well, right now the theming options are very limited without this.

julien’s picture

Instead of a theme function, i did in the meantime a patch so we can choose to display ('.$item['#count'].')' in the facet configuration. See patch attached.

julien’s picture

julien’s picture

StatusFileSize
new1.41 KB

patch is duplicate with the one here: https://www.drupal.org/node/2283177

rooby’s picture

Status: Active » Needs work

Very nice to have that option but it will definitely need a theme function also.
Themers need to be able to override the markup regardless of what has been selected in the settings.

For example they might not want the count wrapped in parentheses or they might want additional spans and classes for styling.

julien’s picture

You mean spans and classes outside the select itself? or are you talking about the select options

julien’s picture

Added a theme function to the select inside the form

julien’s picture

it's 4am, i will finish that patch work later on

rooby’s picture

Oops I mistook this for a different issue. Now that I have properly refreshed my memory...

Markup is not relevant here since we're dealing with select options, so it's just for changing the actual text, like the parentheses, or possibly you want the count at the start or something like that.

rooby’s picture

Overriding the themeing of the whole select is a bit out of the scope of this issue. This one is just for options.

So something to change this:

<?php
$options[$url] = $item['#markup'].' ('.$item['#count'].')';
?>

With something along these lines:

<?php
$options[$url] = theme('facetapi_select_select_option', array(
  'facet_text' => $item['#markup'],
  'facet_count' => $item['#count'],
  'show_count' => $this->settings->settings['count_display'],
));
?>

And then a theme function to print out something like this:

<?php
$output = $variables['facet_text'];

if ($variables['show_count']) {
   $output .= ' (' . $variables['facet_count'] . ')';
}

return $output;
?>

EDIT: Not sure why DRupal.org is messing with the code format.

  • grndlvl committed 97388ea on 7.x-1.x
    Issue #2352419 by julien, rooby: Add theme function for facet options
    
grndlvl’s picture

Status: Needs work » Closed (fixed)
StatusFileSize
new3.72 KB

I agree with rooby as you may now theme the whole form using '#theme' from within a hook_form_alter() now that we have #2136831: Use drupal_get_form() when retrieving the select options form in place.

Attached is a patch of the changes made that will be committed http://drupalcode.org/project/facetapi_select.git/commit/97388ea.