You are here

public function ReplicateFieldSubscriber::onClone in Paragraphs 8

Replicates paragraphs when the parent entity is being replicated.

Parameters

\Drupal\replicate\Events\ReplicateEntityFieldEvent $event:

File

src/EventSubscriber/ReplicateFieldSubscriber.php, line 37

Class

ReplicateFieldSubscriber
Event subscriber that handles cloning through the Replicate module.

Namespace

Drupal\paragraphs\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) {
      $field_item->entity = $this->replicator
        ->replicateEntity($field_item->entity);
    }
  }
}