function apachesolr_entityreference_indexing_callback in Apache Solr Search 8
Same name and namespace in other branches
- 7 apachesolr.index.inc \apachesolr_entityreference_indexing_callback()
Indexing callback for entityreference fields.
Parameters
object $entity:
string $field_name:
string $index_key:
array $field_info:
Return value
array $fields
1 string reference to 'apachesolr_entityreference_indexing_callback'
- entityreference_apachesolr_field_mappings in ./
apachesolr.module - Implements hook_apachesolr_field_mappings() on behalf of EntityReferences (entityreference)
File
- ./
apachesolr.index.inc, line 1297 - Functions related to Apache Solr indexing operations.
Code
function apachesolr_entityreference_indexing_callback($entity, $field_name, $index_key, $field_info) {
$fields = array();
if (!empty($entity->{$field_name}) && array_key_exists(LANGUAGE_NONE, $entity->{$field_name})) {
// Gets entity type and index key. We need to prefix the ID with the entity
// type so we know what entity we are dealing with in the mapping callback.
$entity_type = $field_info['field']['settings']['target_type'];
$index_key = apachesolr_index_key($field_info);
// Iterates over all references and adds them to the fields.
foreach ($entity->{$field_name}[LANGUAGE_NONE] as $reference) {
if ($id = !empty($reference['target_id']) ? $reference['target_id'] : FALSE) {
$fields[] = array(
'key' => $index_key,
'value' => $entity_type . ':' . $id,
);
}
}
}
return $fields;
}