You are here

public function Replicator::cloneByEntityId in Replicate 8

Clone a entity by entity type ID and entity ID without saving.

Parameters

string $entity_type_id: The entity type ID.

int $entity_id: The entity ID.

Return value

\Drupal\Core\Entity\EntityInterface|null The cloned entity.

Throws

\Drupal\Component\Plugin\Exception\PluginNotFoundException Thrown if the entity type doesn't exist.

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException Thrown if the storage handler couldn't be loaded.

File

src/Replicator.php, line 121

Class

Replicator
Class Replicator. Manages the replication of an entity.

Namespace

Drupal\replicate

Code

public function cloneByEntityId($entity_type_id, $entity_id) {
  if ($entity = $this->entityTypeManager
    ->getStorage($entity_type_id)
    ->load($entity_id)) {
    return $this
      ->cloneEntity($entity);
  }
}