...
Note |
---|
Backend documentation need to be added |
Clicking Duplicate from dropdown
...
Controller for displaying form to duplicate existing page
...
Code Block |
---|
class Form extends \Magento\Backend\Block\Template
{
protected $_template = 'MageSuite_CmsDuplicate::form.phtml';
public function getPage()
{
if (!$this->cmsPage) {
$pageId = $this->getRequest()->get('page_id');
$this->cmsPage = $this->pageRepository->getById($pageId);
}
return $this->cmsPage;
}
public function getBlocksToDuplicate()
{
$page = $this->getPage();
$layoutXml = $page->getLayoutUpdateXml();
$components = $this->xmlToComponentConfigurationMapper->map($layoutXml);
$blocks = [];
foreach ($components as $component) {
.....
$blockData = $this->getBlockData($component);
$blocks[] = $blockData;
}
return $blocks;
}
} |
Clicking duplicate
vendor/creativestyle/magesuite-cms-duplicate/Controller/Adminhtml/Duplicate/Duplicate.php:43
Code Block |
---|
class Duplicate extends \Magento\Backend\App\Action
{
public function execute()
{
$data = $this->getRequest()->getPostValue();
/** @var \Magento\Framework\Controller\Result\Json $result */
$result = $this->resultJsonFactory->create();
if ($data) {
try {
$newPage = $this->pageDuplicator->duplicate($data['page_id'], $data['title'], $data['identifier'], $blockData);
}
......
}
return $result;
}
} |
vendor/creativestyle/magesuite-cms-duplicate/Service/PageDuplicator.php:39
Code Block |
---|
class PageDuplicator
{
public function duplicate($oldPageId, $newTitle, $newIdentifier, $blocksData = [])
{
$oldPage = $this->pageRepository->getById($oldPageId);
$duplicatedPage = clone $oldPage;
.....
if (!empty($blocksData)) {
$duplicatedBlocks = $this->duplicateBlocks($blocksData);
$this->assignDuplicatedBlocksToComponents($duplicatedBlocks, $duplicatedPage);
}
$duplicatedPage->save();
return $duplicatedPage;
}
} |
Frontend
No frontend to document.
...