function replicate_clone_entity in Replicate 7
Replicate the entity passed in argument.
This function do not save the replicated entity.
Parameters
string $entity_type: The entity type.
object $entity: The entity to replicate.
Return value
object A new replicated entity.
2 calls to replicate_clone_entity()
- replicate_clone_entity_by_id in ./
replicate.module - Replicate the entity corresponding to the type and id passed in argument.
- replicate_entity in ./
replicate.module - Replicate the entity passed in argument and save it.
File
- ./
replicate.module, line 93 - Main methods of Replicate module.
Code
function replicate_clone_entity($entity_type, $entity) {
$clone = clone $entity;
if ($clone) {
// Let other modules manage the cleaning of the entity.
foreach (module_implements('replicate_entity_' . $entity_type) as $module) {
$function = $module . '_replicate_entity_' . $entity_type;
$function($clone);
}
// Set the entity as new entity.
$clone->is_new = TRUE;
// Reset entity id.
$entity_info = entity_get_info($entity_type);
$clone->{$entity_info['entity keys']['id']} = NULL;
// Reset UUID.
if (isset($entity_info['uuid']) && $entity_info['uuid'] == TRUE && !empty($entity_info['entity keys']['uuid'])) {
$clone->{$entity_info['entity keys']['uuid']} = NULL;
if (!empty($entity_info['entity keys']['revision uuid'])) {
$clone->{$entity_info['entity keys']['revision uuid']} = NULL;
}
}
// Let other modules do special actions on each field.
replicate_clone_fields($clone, $entity_type);
// Let other modules do special actions on the global entity.
drupal_alter('replicate_entity', $clone, $entity_type, $entity);
}
return $clone;
}