Same name in other branches
  1. 2.x src/EntityClone/Config/ConfigEntityCloneBase.php \Drupal\entity_clone\EntityClone\Config\ConfigEntityCloneBase::cloneEntity()

Overrides EntityCloneInterface::cloneEntity

4 methods override ConfigEntityCloneBase::cloneEntity()
ConfigWithFieldEntityClone::cloneEntity dans src/EntityClone/Config/ConfigWithFieldEntityClone.php
Clone an entity.
FieldConfigEntityClone::cloneEntity dans src/EntityClone/Config/FieldConfigEntityClone.php
Clone an entity.
LayoutBuilderEntityClone::cloneEntity dans src/EntityClone/Config/LayoutBuilderEntityClone.php
Clone an entity.
MenuEntityClone::cloneEntity dans src/EntityClone/Config/MenuEntityClone.php
Clone an entity.

Fichier

src/EntityClone/Config/ConfigEntityCloneBase.php, line 57

Classe

ConfigEntityCloneBase
Class Config Entity CloneBase.

Namespace

Drupal\entity_clone\EntityClone\Config

Code

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;
}