You are here

public function ReplicateFieldSubscriber::onClone in Entity Reference with Layout 8

Replicates paragraphs when the parent entity is being replicated.

Parameters

\Drupal\replicate\Events\ReplicateEntityFieldEvent $event:

File

src/EventSubscriber/ReplicateFieldSubscriber.php, line 38

Class

ReplicateFieldSubscriber
Event subscriber that handles cloning through the Replicate module.

Namespace

Drupal\entity_reference_layout\EventSubscriber

Code

public function onClone(ReplicateEntityFieldEvent $event) {
  $field_item_list = $event
    ->getFieldItemList();
  if ($field_item_list
    ->getItemDefinition()
    ->getSetting('target_type') == 'paragraph') {
    foreach ($field_item_list as $field_item) {
      if (!empty($field_item->entity) && $field_item->entity instanceof EntityInterface) {
        $field_item->entity = $this->replicator
          ->replicateEntity($field_item->entity);
      }
    }
  }
}