public function ParagraphsFrontendUIController::duplicate in Paragraphs frontend ui 8
Same name and namespace in other branches
- 8.2 src/Controller/ParagraphsFrontendUIController.php \Drupal\paragraphs_frontend_ui\Controller\ParagraphsFrontendUIController::duplicate()
Duplicate a paragraph.
1 string reference to 'ParagraphsFrontendUIController::duplicate'
File
- src/
Controller/ ParagraphsFrontendUIController.php, line 70
Class
- ParagraphsFrontendUIController
- Controller for up and down actions.
Namespace
Drupal\paragraphs_frontend_ui\ControllerCode
public function duplicate($paragraph, $js = 'nojs') {
$paragraph
->getTranslation($this
->langcode());
extract($this
->getParentData($paragraph));
$paragraph_items = $parent->{$parent_field_name}
->getValue();
$paragraphs_new = [];
foreach ($paragraph_items as $delta => $paragraph_item) {
$paragraphs_new[] = $paragraph_item;
if ($paragraph_item['target_id'] == $paragraph
->id()) {
$cloned_paragraph = $paragraph
->createDuplicate();
$cloned_paragraph
->save();
$paragraphs_new[] = [
'target_id' => $cloned_paragraph
->id(),
'target_revision_id' => $cloned_paragraph
->getRevisionId(),
];
}
}
$parent->{$parent_field_name}
->setValue($paragraphs_new);
$parent
->save();
return $this
->refreshWithAJaxResponse($parent, $parent_field_name);
}