You are here

function _search_api_extract_entity_value in Search API 7

Helper method for extracting the ID (and possibly label) of an entity-valued field.

1 call to _search_api_extract_entity_value()
search_api_extract_fields in ./search_api.module
Extracts specific field values from an EntityMetadataWrapper object.

File

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

Code

function _search_api_extract_entity_value(EntityMetadataWrapper $wrapper, $fulltext = FALSE) {
  $v = $wrapper
    ->value();
  if (is_array($v)) {
    $ret = array();
    foreach ($wrapper as $item) {
      $values = _search_api_extract_entity_value($item, $fulltext);
      if ($values) {
        $ret[] = $values;
      }
    }
    return $ret;
  }
  if ($v) {
    $ret = $wrapper
      ->getIdentifier();
    if ($fulltext && ($label = $wrapper
      ->label())) {
      $ret .= ' ' . $label;
    }
    return $ret;
  }
  return NULL;
}