We have collapsable and expandable facets in use for our project and need some way for the javascript to hook into particular facets.
When looking into the existing classes output, the closest useful classes where these:

  • solr_search_api_inde_type (solr search api index content type)
  • solr_search_api_inde_field_regio (solr search api index region field)

There are 2 problems here:

  1. don't want the garbage solr_search.... stuff
  2. values are trimmed ('inde' instead of index, 'regio' instead of region)

So I did the following:

/**
 * Implements hook_theme().
 */
function esp_theme(&$existing, $type, $theme, $path) {
   $existing['search_api_facets_facet']['variables']['filterName'] = 'will be replaced';
   return array();
}

/**
 * Theme a list of facet links.
 *
 * @param array $variables
 *   An associative array containing:
 *   - terms: An array of available facet terms, as render arrays (or HTML).
 *   - hidden: An array of available facet terms that should initially be hidden.
 *   - active: An array of active facet filters, as render arrays (or HTML).
 */
function esp_search_api_facets_list(array $variables) {
  $items = array();
  
  // !DD note : added the facet name as a class to each <UL> for use as a css/js hook
  $filterName = '';
  
  foreach ($variables['active'] as $filter) {
    $items[] = render($filter);
    $filterName = $filter['#filterName'];
  }
  foreach ($variables['terms'] as $term) {
    $items[] = render($term);
    $filterName = $term['#filterName'];
  }
  foreach ($variables['hidden'] as $term) {
    $items[] = array(
      'data' => render($term),
      'class' => array('element-hidden', 'search-api-facet-link-additional'),
    );
    $filterName = $term['#filterName'];
  }
  
  $filterName = str_replace('field_', '', $filterName);
  $filterName = 'facet_' . $filterName;
  
  return $items ? theme('item_list', array('items' => $items, 'attributes' => array('class' => array('search-api-facets', $filterName)))) : '';
}

and hacked the core...

/**
 * Implements hook_block_view().
 */
function search_api_facets_block_view($delta = '') {

 //... some code is here....

foreach ($terms as $term) {
    ++$count;
    // When limit is set blank or to 0, we want to display all terms.
    $key = ($limit > 0 && $count > $limit) ? '#hidden' : '#terms';
    $theme[$key][] = array(
      '#theme'   => 'search_api_facets_facet' . $theme_suffix,
      '#name'    => $term->name,
      '#count'   => $term->count,
      '#path'    => $_GET['q'],
      '#options' => array('query' => $term->params),
      '#active'  => FALSE,
      // !DD TODO : this change should not be in the module, move to theme when possible
      '#filterName'   => $facet->field,
    );
  }

 //... some code is here....

}

The problem is the whole 'hacking the core' stuff. I didn't want to touch search_api_facets.module but I was left with no choice as I couldn't get a reference to the '$facet->field' in 'function esp_block_view_alter(&$data, $block)'.

Any ideas how to solve this? Ideally I would add the facet class to the block and not the 'UL' tag but I couldn't work that one out.

Comments

drunken monkey’s picture

In the next Beta (and current dev) release, the Facets module is replaced by a whole new module – cf. #1182614: Integrate with Facet API. I guess the problem will then solve itself – or maybe it's there, too, then please report that.

dynamicdan’s picture

I look forward to making the switch to using the Facets module but our project is becoming mature faster than the test/beta stuff would become stable...
I wouldn't be in a position to test this for some months. When the push comes, I will gladly supply a patch if it's missing in the Facets module.

legolasbo’s picture

Status: Active » Closed (outdated)

This issue has not seen activity in over 2,5 years. I am therefore closing this issue to clean up the issue queue. Feel free to re-open and update this issue if you feel this issue is still relevant and of importance.