public function Entity::createDuplicate in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Entity/Entity.php \Drupal\Core\Entity\Entity::createDuplicate()
Creates a duplicate of the entity.
Return value
static A clone of $this with all identifiers unset, so saving it inserts a new entity into the storage system.
Overrides EntityInterface::createDuplicate
1 call to Entity::createDuplicate()
- ConfigEntityBase::createDuplicate in core/
lib/ Drupal/ Core/ Config/ Entity/ ConfigEntityBase.php - Creates a duplicate of the entity.
2 methods override Entity::createDuplicate()
- ConfigEntityBase::createDuplicate in core/
lib/ Drupal/ Core/ Config/ Entity/ ConfigEntityBase.php - Creates a duplicate of the entity.
- ContentEntityBase::createDuplicate in core/
lib/ Drupal/ Core/ Entity/ ContentEntityBase.php - Creates a duplicate of the entity.
File
- core/
lib/ Drupal/ Core/ Entity/ Entity.php, line 383 - Contains \Drupal\Core\Entity\Entity.
Class
- Entity
- Defines a base entity class.
Namespace
Drupal\Core\EntityCode
public function createDuplicate() {
$duplicate = clone $this;
$entity_type = $this
->getEntityType();
// Reset the entity ID and indicate that this is a new entity.
$duplicate->{$entity_type
->getKey('id')} = NULL;
$duplicate
->enforceIsNew();
// Check if the entity type supports UUIDs and generate a new one if so.
if ($entity_type
->hasKey('uuid')) {
$duplicate->{$entity_type
->getKey('uuid')} = $this
->uuidGenerator()
->generate();
}
return $duplicate;
}