You are here

function apachesolr_fields_list_facet_map_callback in Apache Solr Search 8

Same name and namespace in other branches
  1. 6.3 apachesolr.module \apachesolr_fields_list_facet_map_callback()
  2. 7 apachesolr.module \apachesolr_fields_list_facet_map_callback()

Use the list.module's list_allowed_values() to format the field based on its value ($facet).

Parameters

$facet string: The indexed value @param $options An array of options including the hook_block $delta.

2 string references to 'apachesolr_fields_list_facet_map_callback'
field_apachesolr_field_mappings in ./apachesolr.module
Implements hook_apachesolr_field_mappings().
hook_apachesolr_field_mappings in ./apachesolr.api.php
Add index mappings for Field API types. The default mappings array handles just list fields and taxonomy term reference fields, such as:

File

./apachesolr.module, line 2220
Integration with the Apache Solr search application.

Code

function apachesolr_fields_list_facet_map_callback($facets, $options) {
  $map = array();
  $allowed_values = array();

  // @see list_field_formatter_view()
  $fields = field_info_fields();
  $field_name = $options['field']['field_name'];
  if (isset($fields[$field_name])) {
    $allowed_values = list_allowed_values($fields[$field_name]);
  }
  if ($fields[$field_name]['type'] == 'list_boolean') {

    // Convert boolean allowed value keys (0, 1, TRUE, FALSE) to
    // Apache Solr representations (string).
    foreach ($allowed_values as $key => $value) {
      $strkey = $key ? 'true' : 'false';
      $allowed_values[$strkey] = $value;
      unset($allowed_values[$key]);
    }
  }
  foreach ($facets as $key) {
    if (isset($allowed_values[$key])) {
      $map[$key]['#markup'] = field_filter_xss($allowed_values[$key]);
    }
    elseif ($key === '_empty_' && !empty($options['facet missing allowed'])) {

      // Facet missing.
      $map[$key]['#markup'] = theme('facetapi_facet_missing', array(
        'field_name' => $options['display_name'],
      ));
    }
    else {
      $map[$key]['#markup'] = field_filter_xss($key);
    }

    // The value has already been filtered.
    $map[$key]['#html'] = TRUE;
  }
  return $map;
}