-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add PageExportController to bundle
- Loading branch information
Showing
7 changed files
with
209 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
neusta_converter: | ||
converter: | ||
########################################################### | ||
# Import Converter (YamlExportPage -> Page) | ||
########################################################### | ||
neusta_import_page: | ||
target: Pimcore\Model\Document\Page | ||
populators: | ||
- Neusta\Pimcore\ImportExportBundle\Documents\Import\PageImportPopulator | ||
properties: | ||
id: | ||
source: id | ||
default: 0 | ||
key: ~ | ||
title: | ||
source: title | ||
default: 'no title' | ||
controller: | ||
source: controller | ||
default: 'no controller' | ||
type: | ||
source: type | ||
default: 'page' | ||
published: | ||
source: published | ||
default: false | ||
path: | ||
source: path | ||
default: '/' | ||
parentId: | ||
source: parentId | ||
default: 0 | ||
|
||
########################################################### | ||
# Export Converter (Page -> YamlExportPage) | ||
########################################################### | ||
neusta_export_page: | ||
target: Neusta\Pimcore\ImportExportBundle\Documents\Export\YamlExportPage | ||
populators: | ||
- page.property.language.populator | ||
- page.property.navigation_title.populator | ||
- page.property.navigation_name.populator | ||
- page.editables.populator | ||
properties: | ||
id: ~ | ||
key: ~ | ||
title: ~ | ||
controller: ~ | ||
type: ~ | ||
published: ~ | ||
path: ~ | ||
parentId: ~ | ||
|
||
neusta_export_editable_converter: | ||
target: Neusta\Pimcore\ImportExportBundle\Documents\Export\YamlExportEditable | ||
properties: | ||
type: ~ | ||
name: ~ | ||
data: ~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
page_export: | ||
resource: '@NeustaPimcoreImportExportBundle/Controller/Admin/PageExportController.php' | ||
type: annotation | ||
options: | ||
expose: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// /Resources/public/js/exportPage.js | ||
pimcore.registerNS("pimcore.plugin.page.export"); | ||
|
||
pimcore.plugin.page.export = Class.create({ | ||
initialize: function () { | ||
document.addEventListener(pimcore.events.prepareDocumentTreeContextMenu, this.onPrepareDocumentTreeContextMenu.bind(this)); | ||
}, | ||
|
||
onPrepareDocumentTreeContextMenu: function (e) { | ||
let menu = e.detail.menu; | ||
let document = e.detail.document; | ||
// Export page into yaml file | ||
menu.add("-"); | ||
menu.add(new Ext.menu.Item({ | ||
text: 'Export to yaml', | ||
iconCls: "pimcore_icon_export", | ||
handler: function () { | ||
pimcore.helpers.download(Routing.generate('page_export', {page_id: document.data.id})); | ||
} | ||
})); | ||
}, | ||
|
||
}); | ||
|
||
var pimcorePluginPageExport = new pimcore.plugin.page.export(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Neusta\Pimcore\ImportExportBundle\Controller\Admin; | ||
|
||
use Neusta\Pimcore\ImportExportBundle\Documents\Export\PageExporter; | ||
use Neusta\Pimcore\ImportExportBundle\Toolbox\Repository\PageRepository; | ||
use Pimcore\Controller\UserAwareController; | ||
use Pimcore\Model\Document\Page; | ||
use Symfony\Component\HttpFoundation\HeaderUtils; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
final class PageExportController extends UserAwareController | ||
{ | ||
public function __construct( | ||
private PageExporter $pageExporter, | ||
private PageRepository $pageRepository, | ||
) { | ||
} | ||
|
||
/** | ||
* @Route("/admin/page/export", name="page_export", methods={"GET"}) | ||
*/ | ||
public function exportPage(Request $request): Response | ||
{ | ||
$pageId = $request->get('page_id'); | ||
$page = $this->pageRepository->getById($pageId); | ||
|
||
if (!$page instanceof Page) { | ||
return new JsonResponse( | ||
\sprintf('Page with id "%s" was not found', $pageId), | ||
Response::HTTP_NOT_FOUND, | ||
); | ||
} | ||
|
||
try { | ||
$json = $this->pageExporter->toYaml($page); | ||
} catch (\Exception $e) { | ||
return new JsonResponse($e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); | ||
} | ||
|
||
$response = new Response($json); | ||
$response->headers->set('Content-type', 'application/json'); | ||
$response->headers->set( | ||
'Content-Disposition', | ||
HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, $this->createFilename($page)), | ||
); | ||
|
||
return $response; | ||
} | ||
|
||
private function createFilename(Page $page): string | ||
{ | ||
return \sprintf('%s.yaml', str_replace(' ', '_', (string) $page->getKey())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Neusta\PimcoreImportExportBundle\EventListener; | ||
|
||
use Pimcore\Event\BundleManager\PathsEvent; | ||
|
||
final class PimcoreAdminListener | ||
{ | ||
public function addJSFiles(PathsEvent $event): void | ||
{ | ||
$event->setPaths(array_merge( | ||
$event->getPaths(), | ||
[ | ||
'/bundles/neustapimcoreimportexport/js/exportPage.js', | ||
], | ||
)); | ||
} | ||
} |