public function createDuplicate() {
$duplicate = parent::createDuplicate();
// Loop over entity fields and duplicate nested paragraphs.
foreach ($duplicate
->getFields() as $fieldItemList) {
if ($fieldItemList instanceof EntityReferenceFieldItemListInterface && $fieldItemList
->getSetting('target_type') === $this
->getEntityTypeId()) {
foreach ($fieldItemList as $delta => $item) {
if ($item->entity) {
$fieldItemList[$delta] = $item->entity
->createDuplicate();
}
}
}
}
return $duplicate;
}