function ContentEntityBase::createDuplicate
Overrides EntityBase::createDuplicate
1 call to ContentEntityBase::createDuplicate()
- BlockContent::createDuplicate in core/modules/ block_content/ src/ Entity/ BlockContent.php 
- Creates a duplicate of the entity.
1 method overrides ContentEntityBase::createDuplicate()
- BlockContent::createDuplicate in core/modules/ block_content/ src/ Entity/ BlockContent.php 
- Creates a duplicate of the entity.
File
- 
              core/lib/ Drupal/ Core/ Entity/ ContentEntityBase.php, line 1204 
Class
- ContentEntityBase
- Implements Entity Field API specific enhancements to the Entity class.
Namespace
Drupal\Core\EntityCode
public function createDuplicate() {
  if ($this->translations[$this->activeLangcode]['status'] == static::TRANSLATION_REMOVED) {
    throw new \InvalidArgumentException("The entity object refers to a removed translation ({$this->activeLangcode}) and cannot be manipulated.");
  }
  $duplicate = clone $this;
  $entity_type = $this->getEntityType();
  if ($entity_type->hasKey('id')) {
    $duplicate->{$entity_type->getKey('id')}->value = NULL;
  }
  // Explicitly mark the entity as new and the default revision. A new entity
  // is always the default revision, but that persists only until the entity
  // is saved.
  $duplicate->enforceIsNew();
  $duplicate->isDefaultRevision(TRUE);
  // Check if the entity type supports UUIDs and generate a new one if so.
  if ($entity_type->hasKey('uuid')) {
    $duplicate->{$entity_type->getKey('uuid')}->value = $this->uuidGenerator()
      ->generate();
  }
  // Check whether the entity type supports revisions and initialize it if so.
  if ($entity_type->isRevisionable()) {
    $duplicate->{$entity_type->getKey('revision')}->value = NULL;
    $duplicate->loadedRevisionId = NULL;
  }
  // Modules might need to add or change the data initially held by the new
  // entity object, for instance to fill-in default values.
  \Drupal::moduleHandler()->invokeAll($this->getEntityTypeId() . '_duplicate', [
    $duplicate,
    $this,
  ]);
  \Drupal::moduleHandler()->invokeAll('entity_duplicate', [
    $duplicate,
    $this,
  ]);
  return $duplicate;
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
