public function FileEntityClone::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/ FileEntityClone.php, line 16
Class
- FileEntityClone
- Class ContentEntityCloneBase.
Namespace
Drupal\entity_clone\EntityClone\ContentCode
public function cloneEntity(EntityInterface $entity, EntityInterface $cloned_entity, array $properties = [], array &$already_cloned = []) {
/** @var \Drupal\file\FileInterface $cloned_entity */
$cloned_file = file_copy($cloned_entity, $cloned_entity
->getFileUri(), FileSystemInterface::EXISTS_RENAME);
if (isset($properties['take_ownership']) && $properties['take_ownership'] === 1) {
$cloned_file
->setOwnerId(\Drupal::currentUser()
->id());
}
return parent::cloneEntity($entity, $cloned_file, $properties);
}