You are here

function cer_get_field_collection_lineage_array in Corresponding Entity References 7.3

Gets a field collection's lineage as an array.

1 call to cer_get_field_collection_lineage_array()
cer_get_field_collection_depth in ./cer.properties.field_collection.inc
Gets the zero-based depth of a field collection.
1 string reference to 'cer_get_field_collection_lineage_array'
cer_entity_property_info_alter in ./cer.module
Implements hook_entity_property_info_alter().

File

./cer.properties.field_collection.inc, line 22
Contains entity property callback functions for the 'cer' struct exposed to Entity API on field collections.

Code

function cer_get_field_collection_lineage_array(array $data, array $options, $property, $data_type, array $info) {
  $collection = $data[1];

  // If this is the innermost entity, $options['lineage'] will be empty.
  if (!isset($options['lineage'])) {
    $options['lineage'][] = "field_collection_item:{$collection->field_name}:";
  }
  $data[0] = $collection
    ->hostEntityType();
  $data[1] = $collection
    ->hostEntity();
  if (!$data[1]) {
    return $options['lineage'];
  }
  list(, , $host_bundle) = entity_extract_IDs($data[0], $data[1]);
  array_unshift($options['lineage'], $data[0] . ":{$host_bundle}:{$collection->field_name}");

  // If this field collection is hosted in another field collection, recurse
  // upward. Otherwise, we're done; return the lineage array.
  if ($data[0] == 'field_collection_item') {
    return cer_get_field_collection_lineage_array($data, $options, $property, $data_type, $info);
  }
  else {
    return $options['lineage'];
  }
}