Same name in other branches
- 2.x src/EntityClone/Config/ConfigWithFieldEntityClone.php \Drupal\entity_clone\EntityClone\Config\ConfigWithFieldEntityClone::cloneEntity()
Overrides ConfigEntityCloneBase::cloneEntity
File
-
src/
EntityClone/ Config/ ConfigWithFieldEntityClone.php, line 16
Class
- ConfigWithFieldEntityClone
- Class Content Entity Clone Base.
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;
}