You are here

protected function ConfigWithFieldEntityClone::cloneDisplays in Entity Clone 8

Clone all fields. Each field re-use existing field storage.

Parameters

string $type: The type of display (view or form).

string $entity_id: The base entity ID.

string $cloned_entity_id: The cloned entity ID.

array $view_displays: All view available display for this type.

string $bundle_of: The bundle of the cloned entity.

1 call to ConfigWithFieldEntityClone::cloneDisplays()
ConfigWithFieldEntityClone::cloneEntity in src/EntityClone/Config/ConfigWithFieldEntityClone.php
Clone an entity.

File

src/EntityClone/Config/ConfigWithFieldEntityClone.php, line 87

Class

ConfigWithFieldEntityClone
Class ContentEntityCloneBase.

Namespace

Drupal\entity_clone\EntityClone\Config

Code

protected function cloneDisplays($type, $entity_id, $cloned_entity_id, array $view_displays, $bundle_of) {
  foreach ($view_displays as $view_display_id => $view_display) {

    /** @var \Drupal\Core\Entity\Display\EntityDisplayInterface $display */
    $display = $this->entityTypeManager
      ->getStorage('entity_' . $type . '_display')
      ->load($bundle_of . '.' . $entity_id . '.' . $view_display_id);
    if ($display) {

      /** @var \Drupal\entity_clone\EntityClone\EntityCloneInterface $view_display_clone_handler */
      $view_display_clone_handler = $this->entityTypeManager
        ->getHandler($this->entityTypeManager
        ->getDefinition($display
        ->getEntityTypeId())
        ->id(), 'entity_clone');
      $view_display_properties = [
        'id' => $bundle_of . '.' . $cloned_entity_id . '.' . $view_display_id,
      ];
      $cloned_view_display = $display
        ->createDuplicate();
      $cloned_view_display
        ->set('bundle', $cloned_entity_id);
      $view_display_clone_handler
        ->cloneEntity($display, $cloned_view_display, $view_display_properties);
    }
  }
}