public function Replicator::replicateByEntityId in Replicate 8
Replicate a entity by entity type ID and entity ID and save it.
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.
\Drupal\Core\Entity\EntityStorageException In case of failures, an exception is thrown.
File
- src/
Replicator.php, line 74
Class
- Replicator
- Class Replicator. Manages the replication of an entity.
Namespace
Drupal\replicateCode
public function replicateByEntityId($entity_type_id, $entity_id) {
if ($entity = $this->entityTypeManager
->getStorage($entity_type_id)
->load($entity_id)) {
return $this
->replicateEntity($entity);
}
}