public function ConfigWithFieldEntityClone::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 ConfigEntityCloneBase::cloneEntity
File
- src/
EntityClone/ Config/ ConfigWithFieldEntityClone.php, line 16
Class
- ConfigWithFieldEntityClone
- Class ContentEntityCloneBase.
Namespace
Drupal\entity_clone\EntityClone\ConfigCode
public function cloneEntity(EntityInterface $entity, EntityInterface $cloned_entity, array $properties = []) {
$cloned_entity = parent::cloneEntity($entity, $cloned_entity, $properties);
$bundle_of = $cloned_entity
->getEntityType()
->getBundleOf();
if ($bundle_of) {
$this
->cloneFields($entity
->id(), $cloned_entity
->id(), $bundle_of);
}
$view_displays = \Drupal::service('entity_display.repository')
->getFormModes($bundle_of);
$view_displays = array_merge($view_displays, [
'default' => 'default',
]);
if (!empty($view_displays)) {
$this
->cloneDisplays('form', $entity
->id(), $cloned_entity
->id(), $view_displays, $bundle_of);
}
$view_displays = \Drupal::service('entity_display.repository')
->getViewModes($bundle_of);
$view_displays = array_merge($view_displays, [
'default' => 'default',
]);
if (!empty($view_displays)) {
$this
->cloneDisplays('view', $entity
->id(), $cloned_entity
->id(), $view_displays, $bundle_of);
}
return $cloned_entity;
}