You are here

function apachesolr_multilingual_entityreference_indexing_callback_implementation in Apache Solr Multilingual 7

Indexing callback for entityreference fields.

Parameters

object $entity:

string $field_name:

string $index_key:

array $field_info:

Return value

array $fields

1 call to apachesolr_multilingual_entityreference_indexing_callback_implementation()
apachesolr_multilingual_entityreference_indexing_callback in ./apachesolr_multilingual.module
Indexing callback for entityreference fields.

File

./apachesolr_multilingual.index.inc, line 247

Code

function apachesolr_multilingual_entityreference_indexing_callback_implementation($entity, $field_name, $index_key, $field_info) {
  $fields = array();
  if (!empty($entity->{$field_name})) {
    if (array_key_exists($entity->language, $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}[$entity->language] as $reference) {
        if ($id = !empty($reference['target_id']) ? $reference['target_id'] : FALSE) {
          $fields[] = array(
            'key' => $index_key,
            'value' => $entity_type . ':' . $id,
          );
        }
      }
    }
    else {
      return apachesolr_entityreference_indexing_callback($entity, $field_name, $index_key, $field_info);
    }
  }
  return $fields;
}