Same name in other branches
- 8.x-1.x src/EntityClone/Config/ConfigWithFieldEntityClone.php \Drupal\entity_clone\EntityClone\Config\ConfigWithFieldEntityClone::cloneFields()
Clone all fields. Each field re-use existing field storage.
Paramètres
string $entity_id: The base entity ID.
string $cloned_entity_id: The cloned entity ID.
string $bundle_of: The bundle of the cloned entity.
1 call to ConfigWithFieldEntityClone::cloneFields()
- ConfigWithFieldEntityClone::cloneEntity dans src/
EntityClone/ Config/ ConfigWithFieldEntityClone.php - Clone an entity.
Fichier
-
src/
EntityClone/ Config/ ConfigWithFieldEntityClone.php, line 48
Classe
- ConfigWithFieldEntityClone
- Class Content Entity Clone Base.
Namespace
Drupal\entity_clone\EntityClone\ConfigCode
protected function cloneFields($entity_id, $cloned_entity_id, $bundle_of) {
/** @var \Drupal\Core\Entity\EntityFieldManager $field_manager */
$field_manager = \Drupal::service('entity_field.manager');
$fields = $field_manager->getFieldDefinitions($bundle_of, $entity_id);
foreach ($fields as $field_definition) {
if ($field_definition instanceof FieldConfigInterface) {
if ($this->entityTypeManager
->hasHandler($this->entityTypeManager
->getDefinition($field_definition->getEntityTypeId())
->id(), 'entity_clone')) {
/** @var \Drupal\entity_clone\EntityClone\EntityCloneInterface $field_config_clone_handler */
$field_config_clone_handler = $this->entityTypeManager
->getHandler($this->entityTypeManager
->getDefinition($field_definition->getEntityTypeId())
->id(), 'entity_clone');
$field_config_properties = [
'id' => $field_definition->getName(),
'label' => $field_definition->label(),
'skip_storage' => TRUE,
];
$cloned_field_definition = $field_definition->createDuplicate();
$cloned_field_definition->set('bundle', $cloned_entity_id);
$field_config_clone_handler->cloneEntity($field_definition, $cloned_field_definition, $field_config_properties);
}
}
}
}