You are here

function apachesolr_entityreference_content_indexing_callback in Apachesolr Entityreference Content 7

Indexing callback for entityreference fields.

1 string reference to 'apachesolr_entityreference_content_indexing_callback'
apachesolr_entityreference_content_apachesolr_field_mappings in ./apachesolr_entityreference_content.module
Implements hook_apachesolr_field_mappings().

File

./apachesolr_entityreference_content.module, line 22
Functionality for including content from referenced entity field contents in Apache Solr index.

Code

function apachesolr_entityreference_content_indexing_callback($entity, $field_name, $index_key, $field_info) {
  $fields = array();
  if (!empty($entity->{$field_name})) {
    $entity_type = $field_info['field']['settings']['target_type'];
    $referenced_entities = array();
    if (isset($entity->{$field_name}[$entity->language])) {
      $referenced_entities = $entity->{$field_name}[$entity->language];
    }
    elseif (isset($entity->{$field_name}[LANGUAGE_NONE])) {
      $referenced_entities = $entity->{$field_name}[LANGUAGE_NONE];
    }

    // Iterates over all references.
    foreach ($referenced_entities as $reference) {

      // Index the fields from the referenced entities.
      apachesolr_entityreference_content_add_entity_fields($fields, $entity_type, $reference['entity']);
    }
  }
  return $fields;
}