Same name in other branches
- 2.x src/EntityClone/Config/ConfigEntityCloneBase.php \Drupal\entity_clone\EntityClone\Config\ConfigEntityCloneBase::cloneEntity()
Overrides EntityCloneInterface::cloneEntity
4 methods override ConfigEntityCloneBase::cloneEntity()
- ConfigWithFieldEntityClone::cloneEntity in src/
EntityClone/ Config/ ConfigWithFieldEntityClone.php - Clone an entity.
- FieldConfigEntityClone::cloneEntity in src/
EntityClone/ Config/ FieldConfigEntityClone.php - Clone an entity.
- LayoutBuilderEntityClone::cloneEntity in src/
EntityClone/ Config/ LayoutBuilderEntityClone.php - Clone an entity.
- MenuEntityClone::cloneEntity in src/
EntityClone/ Config/ MenuEntityClone.php - Clone an entity.
File
-
src/
EntityClone/ Config/ ConfigEntityCloneBase.php, line 57
Class
- ConfigEntityCloneBase
- Class Config Entity CloneBase.
Namespace
Drupal\entity_clone\EntityClone\ConfigCode
public function cloneEntity(EntityInterface $entity, EntityInterface $cloned_entity, array $properties = []) {
/** @var \Drupal\core\Config\Entity\ConfigEntityInterface $cloned_entity */
$id_key = $this->entityTypeManager
->getDefinition($this->entityTypeId)
->getKey('id');
$label_key = $this->entityTypeManager
->getDefinition($this->entityTypeId)
->getKey('label');
// Set new entity properties.
if (isset($properties['id'])) {
if ($id_key) {
$cloned_entity->set($id_key, $properties['id']);
}
unset($properties['id']);
}
if (isset($properties['label'])) {
if ($label_key) {
$cloned_entity->set($label_key, $properties['label']);
}
unset($properties['label']);
}
foreach ($properties as $key => $property) {
$cloned_entity->set($key, $property);
}
$cloned_entity->save();
return $cloned_entity;
}