FieldConfigEntityClone.php in Entity Clone 8
File
src/EntityClone/Config/FieldConfigEntityClone.php
View source
<?php
namespace Drupal\entity_clone\EntityClone\Config;
use Drupal\Core\Entity\EntityInterface;
class FieldConfigEntityClone extends ConfigEntityCloneBase {
public function cloneEntity(EntityInterface $field_config, EntityInterface $cloned_field_config, array $properties = []) {
if (!isset($properties['skip_storage']) || !$properties['skip_storage']) {
$cloned_field_storage = $field_config
->getFieldStorageDefinition()
->createDuplicate();
$cloned_field_storage
->set('field_name', $properties['id']);
$cloned_field_storage
->set('id', $properties['id'] . '.' . $cloned_field_storage
->getTargetEntityTypeId());
$cloned_field_storage
->save();
}
unset($properties['skip_storage']);
$properties['field_name'] = $properties['id'];
$properties['id'] = $cloned_field_config
->getTargetEntityTypeId() . '.' . $cloned_field_config
->getTargetBundle() . '.' . $properties['id'];
return parent::cloneEntity($field_config, $cloned_field_config, $properties);
}
}