You are here

public function FieldConfigEntityClone::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/FieldConfigEntityClone.php, line 15

Class

FieldConfigEntityClone
Class FieldConfigEntityClone.

Namespace

Drupal\entity_clone\EntityClone\Config

Code

public function cloneEntity(EntityInterface $field_config, EntityInterface $cloned_field_config, array $properties = []) {

  /** @var \Drupal\field\Entity\FieldConfig $field_config */

  /** @var \Drupal\field\Entity\FieldConfig $cloned_field_config */

  /** @var \Drupal\field\Entity\FieldStorageConfig $cloned_field_storage */
  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);
}