You are here

function entity_ui_clone_entity in Entity API 7

Clones the entity object and makes sure it will get saved as new entity.

Return value

object The cloned entity object.

1 call to entity_ui_clone_entity()
entity_ui_get_form in ./entity.module
A wrapper around drupal_get_form() that helps building entity forms.

File

includes/entity.ui.inc, line 661
Provides a controller for building an entity overview form.

Code

function entity_ui_clone_entity($entity_type, $entity) {

  // Clone the entity and make sure it will get saved as a new entity.
  $entity = clone $entity;
  $entity_info = entity_get_info($entity_type);
  $entity->{$entity_info['entity keys']['id']} = FALSE;
  if (!empty($entity_info['entity keys']['name'])) {
    $entity->{$entity_info['entity keys']['name']} = FALSE;
  }
  $entity->is_new = TRUE;

  // Make sure the status of a cloned exportable is custom.
  if (!empty($entity_info['exportable'])) {
    $status_key = isset($entity_info['entity keys']['status']) ? $entity_info['entity keys']['status'] : 'status';
    $entity->{$status_key} = ENTITY_CUSTOM;
  }
  return $entity;
}