public function EntityNG::createDuplicate

Overrides Entity::createDuplicate().

Overrides Entity::createDuplicate

1 call to EntityNG::createDuplicate()
CustomBlock::createDuplicate in drupal/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlock.php
Overrides Entity::createDuplicate().
1 method overrides EntityNG::createDuplicate()
CustomBlock::createDuplicate in drupal/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlock.php
Overrides Entity::createDuplicate().

File

drupal/core/lib/Drupal/Core/Entity/EntityNG.php, line 545
Contains \Drupal\Core\Entity\EntityNG.

Class

EntityNG
Implements Entity Field API specific enhancements to the Entity class.

Namespace

Drupal\Core\Entity

Code

public function createDuplicate() {
  $duplicate = clone $this;
  $entity_info = $this
    ->entityInfo();
  $duplicate->{$entity_info['entity_keys']['id']}->value = NULL;

  // Check if the entity type supports UUIDs and generate a new one if so.
  if (!empty($entity_info['entity_keys']['uuid'])) {
    $uuid = new Uuid();
    $duplicate->{$entity_info['entity_keys']['uuid']}->value = $uuid
      ->generate();
  }

  // Check whether the entity type supports revisions and initialize it if so.
  if (!empty($entity_info['entity_keys']['revision'])) {
    $duplicate->{$entity_info['entity_keys']['revision']}->value = NULL;
  }
  return $duplicate;
}