class ReplicateFieldSubscriber in Paragraphs 8
Event subscriber that handles cloning through the Replicate module.
Hierarchy
- class \Drupal\paragraphs\EventSubscriber\ReplicateFieldSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of ReplicateFieldSubscriber
File
- src/
EventSubscriber/ ReplicateFieldSubscriber.php, line 13
Namespace
Drupal\paragraphs\EventSubscriberView source
class ReplicateFieldSubscriber implements EventSubscriberInterface {
/**
* The replicator service.
*
* @var \Drupal\replicate\Replicator
*/
protected $replicator;
/**
* ReplicateFieldSubscriber constructor.
*
* @param \Drupal\replicate\Replicator $replicator
* The replicator service.
*/
public function __construct(Replicator $replicator) {
$this->replicator = $replicator;
}
/**
* Replicates paragraphs when the parent entity is being replicated.
*
* @param \Drupal\replicate\Events\ReplicateEntityFieldEvent $event
*/
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);
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[ReplicatorEvents::replicateEntityField('entity_reference_revisions')][] = 'onClone';
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ReplicateFieldSubscriber:: |
protected | property | The replicator service. | |
ReplicateFieldSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
ReplicateFieldSubscriber:: |
public | function | Replicates paragraphs when the parent entity is being replicated. | |
ReplicateFieldSubscriber:: |
public | function | ReplicateFieldSubscriber constructor. |