You are here

function search_api_get_sanitized_field_values in Search API 7

Sanitizes field values returned from the server.

Parameters

array $values: The field values, as returned from the server. See SearchApiQueryInterface::execute() for documentation on the structure.

Return value

array An associative array of field IDs mapped to their sanitized values (scalar or array-valued).

2 calls to search_api_get_sanitized_field_values()
SearchApiHighlight::getFulltextFields in includes/processor_highlight.inc
Retrieves the fulltext data of a result.
SearchApiViewsQuery::addResults in contrib/search_api_views/includes/query.inc
Helper function for adding results to a view in the format expected by the view.

File

./search_api.module, line 3069
Provides a flexible framework for implementing search services.

Code

function search_api_get_sanitized_field_values(array $values) {

  // Sanitize the field values returned from the server. Usually we use
  // check_plain(), but this can be overridden by setting the field value to
  // an array with "#value" and "#sanitize_callback" keys.
  foreach ($values as $field_id => $field_value) {
    if (is_array($field_value) && isset($field_value['#sanitize_callback']) && ($field_value['#sanitize_callback'] === FALSE || is_callable($field_value['#sanitize_callback'])) && array_key_exists('#value', $field_value)) {
      $sanitize_callback = $field_value['#sanitize_callback'];
      $field_value = $field_value['#value'];
    }
    else {
      $sanitize_callback = 'check_plain';
    }
    if ($sanitize_callback !== FALSE) {
      $field_value = search_api_sanitize_field_value($field_value, $sanitize_callback);
    }
    $values[$field_id] = $field_value;
  }
  return $values;
}