Same name in other branches
- 8.x-1.x src/EntityClone/Config/ConfigWithFieldEntityClone.php \Drupal\entity_clone\EntityClone\Config\ConfigWithFieldEntityClone::cloneEntity()
Overrides ConfigEntityCloneBase::cloneEntity
Fichier
-
src/
EntityClone/ Config/ ConfigWithFieldEntityClone.php, line 16
Classe
- 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;
}