Skip to content

Commit 0d80f50

Browse files
authored
Merge pull request #24 from bennybobw/23-undefined-function
Fix call to undefined function Fixes Issue #23
2 parents bb32e59 + 2d65e70 commit 0d80f50

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

field_collection.module

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,7 @@ function field_collection_entity_translation_source_field_state_alter(&$field_st
14351435
module_load_include('inc', 'entity', 'includes/entity.ui');
14361436
foreach ($field_state['entity'] as $delta => $entity) {
14371437
if ($entity instanceof FieldCollectionItemEntity) {
1438-
$field_state['entity'][$delta] = entity_ui_clone_entity('field_collection_item', $entity);
1438+
$field_state['entity'][$delta] = field_collection_clone_entity('field_collection_item', $entity);
14391439
}
14401440
}
14411441
}
@@ -2520,3 +2520,28 @@ function field_collection_feeds_presave(FeedsSource $source, $entity, $item, $en
25202520
}
25212521
}
25222522
}
2523+
2524+
/**
2525+
* Clones the entity object and makes sure it will get saved as new entity.
2526+
*
2527+
* @return object
2528+
* The cloned entity object.
2529+
*/
2530+
function field_collection_clone_entity($entity_type, $entity) {
2531+
// Clone the entity and make sure it will get saved as a new entity.
2532+
$entity = clone $entity;
2533+
2534+
$entity_info = entity_get_info($entity_type);
2535+
$entity->{$entity_info['entity keys']['id']} = FALSE;
2536+
if (!empty($entity_info['entity keys']['name'])) {
2537+
$entity->{$entity_info['entity keys']['name']} = FALSE;
2538+
}
2539+
$entity->is_new = TRUE;
2540+
2541+
// Make sure the status of a cloned exportable is custom.
2542+
if (!empty($entity_info['exportable'])) {
2543+
$status_key = isset($entity_info['entity keys']['status']) ? $entity_info['entity keys']['status'] : 'status';
2544+
$entity->$status_key = ENTITY_CUSTOM;
2545+
}
2546+
return $entity;
2547+
}

0 commit comments

Comments
 (0)