You are here

function field_collection_item_set_host_entity in Field collection 7

Entity property info setter callback for the host entity property.

As the property is of type entity, the value will be passed as a wrapped entity.

1 string reference to 'field_collection_item_set_host_entity'
FieldCollectionItemMetadataController::entityPropertyInfo in ./field_collection.info.inc

File

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

Code

function field_collection_item_set_host_entity($item, $property_name, $wrapper) {
  if (empty($item->is_new)) {
    throw new EntityMetadataWrapperException('The host entity may be set only during creation of a field collection item.');
  }
  if (!isset($wrapper->{$item->field_name})) {
    throw new EntityMetadataWrapperException('The specified entity has no such field collection field.');
  }
  $entity_type = $wrapper
    ->type();
  $field = field_info_field($item->field_name);
  $langcode = field_is_translatable($entity_type, $field) ? field_collection_entity_language($entity_type, $wrapper
    ->value()) : LANGUAGE_NONE;
  $item
    ->setHostEntity($wrapper
    ->type(), $wrapper
    ->value(), $langcode);
}