You are here

function field_collection_field_get_entity in Field collection 7

Gets a field collection item entity for a given field item.

Parameters

$field_name: (optional) If given and there is no entity yet, a new entity object is created for the given item.

Return value

The entity object or FALSE.

7 calls to field_collection_field_get_entity()
field_collection_entity_translation_delete in ./field_collection.module
Implements hook_entity_translation_delete().
field_collection_entity_translation_insert in ./field_collection.module
Implements hook_entity_translation_insert().
field_collection_field_formatter_view in ./field_collection.module
Implements hook_field_formatter_view().
field_collection_field_insert in ./field_collection.module
Implements hook_field_insert().
field_collection_field_property_get in ./field_collection.module
Entity property info getter callback for the field collection items.

... See full list

File

./field_collection.module, line 1677
Module implementing field collection field type.

Code

function field_collection_field_get_entity(&$item, $field_name = NULL) {
  if (isset($item['entity']) && $item['entity']
    ->entityType() == 'field_collection_item') {
    if (count($item) > 1) {

      // If $item contains more thing than 'entity', then it is sent from VBO.
      // We clone the object to avoid that the same field collection item of the
      // faked object is attached to multiple host objects.
      return clone $item['entity'];
    }
    return $item['entity'];
  }
  if (isset($item['value'])) {

    // By default always load the default revision, so caches get used.
    $entity = field_collection_item_load($item['value']);
    if ($entity && $entity->revision_id != $item['revision_id']) {

      // A non-default revision is a referenced, so load this one.
      $entity = field_collection_item_revision_load($item['revision_id']);
    }
    return $entity;
  }
  if (isset($field_name) && !isset($item['entity'])) {
    $item['entity'] = entity_create('field_collection_item', array(
      'field_name' => $field_name,
    ));
    return $item['entity'];
  }
  return FALSE;
}