You are here

function _slickgrid_clone_entity in Slickgrid 7.2

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

This is a fixed version of "entity_ui_clone_entity"

1 call to _slickgrid_clone_entity()
slickgrid_clone_form_submit in includes/slickgrid.form.inc
Submit function for the clone of entities.

File

includes/slickgrid.form.inc, line 138

Code

function _slickgrid_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;
  }
  if (!empty($entity_info['entity keys']['revision'])) {
    $entity->{$entity_info['entity keys']['revision']} = FALSE;
  }
  if (!empty($entity_info['entity keys']['uuid'])) {
    $entity->{$entity_info['entity keys']['uuid']} = FALSE;
  }
  if (!empty($entity_info['entity keys']['vuuid'])) {
    $entity->{$entity_info['entity keys']['vuuid']} = 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;
}