You are here

public function TaxonomyTermEntityClone::cloneEntity in Entity Clone 8

Clone an entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity.

\Drupal\Core\Entity\EntityInterface $cloned_entity: The cloned entity.

array $properties: All new properties to replace old.

Return value

\Drupal\Core\Entity\EntityInterface The new saved entity.

Overrides ContentEntityCloneBase::cloneEntity

File

src/EntityClone/Content/TaxonomyTermEntityClone.php, line 15

Class

TaxonomyTermEntityClone
Class TaxonomyTermEntityClone.

Namespace

Drupal\entity_clone\EntityClone\Content

Code

public function cloneEntity(EntityInterface $entity, EntityInterface $cloned_entity, array $properties = [], array &$already_cloned = []) {

  /** @var \Drupal\core\Entity\ContentEntityInterface $cloned_entity */

  // Enforce a parent if the cloned term doesn't have a parent.
  // (First level of a taxonomy tree).
  if (!isset($cloned_entity->parent->target_id)) {
    $cloned_entity
      ->set('parent', 0);
  }
  return parent::cloneEntity($entity, $cloned_entity, $properties);
}