You are here

public function EntityInlineEntityFormController::createClone in Inline Entity Form 7

Creates a clone of the given entity.

Copies the entity_ui_clone_entity() approach, extending it to unset additional unique properties.

Parameters

$entity: The entity to clone.

Return value

The unsaved cloned entity.

2 calls to EntityInlineEntityFormController::createClone()
CommerceProductInlineEntityFormController::createClone in includes/commerce_product.inline_entity_form.inc
Overrides EntityInlineEntityFormController::createClone().
NodeInlineEntityFormController::createClone in includes/node.inline_entity_form.inc
Overrides EntityInlineEntityFormController::createClone().
2 methods override EntityInlineEntityFormController::createClone()
CommerceProductInlineEntityFormController::createClone in includes/commerce_product.inline_entity_form.inc
Overrides EntityInlineEntityFormController::createClone().
NodeInlineEntityFormController::createClone in includes/node.inline_entity_form.inc
Overrides EntityInlineEntityFormController::createClone().

File

includes/entity.inline_entity_form.inc, line 397
Defines the base inline entity form controller.

Class

EntityInlineEntityFormController
@file Defines the base inline entity form controller.

Code

public function createClone($entity) {
  $cloned_entity = clone $entity;
  $cloned_entity->is_new = TRUE;
  $entity_info = entity_get_info($this->entityType);

  // 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';
    $cloned_entity->{$status_key} = ENTITY_CUSTOM;
  }

  // Unset properties specified as entity keys.
  foreach (array(
    'id',
    'name',
    'revision',
  ) as $key) {
    if (!empty($entity_info['entity keys'][$key])) {
      $cloned_entity->{$entity_info['entity keys'][$key]} = NULL;
    }
  }

  // Unset other common properties.
  foreach (array(
    'created',
    'changed',
    'uid',
    'revision_timestamp',
    'revision_uid',
  ) as $property) {
    if (isset($cloned_entity->{$property})) {
      $cloned_entity->{$property} = NULL;
    }
  }
  return $cloned_entity;
}