From ebca27006fa938ca322b2110d3d05f17debff2d7 Mon Sep 17 00:00:00 2001 From: Johannes Wachter Date: Fri, 14 Apr 2017 09:40:23 +0200 Subject: [PATCH 1/2] added synchronice children between draft and live --- Controller/ArticlePageController.php | 5 - Document/Behavior/PageBehavior.php | 3 +- Document/Subscriber/ArticlePageSubscriber.php | 18 ++- Document/Subscriber/ArticleSubscriber.php | 43 +++++++ Document/Subscriber/PageSubscriber.php | 8 +- Document/Subscriber/RoutableSubscriber.php | 36 ++++-- Resources/config/services.xml | 1 + Resources/translations/sulu/backend.de.xlf | 2 +- .../Subscriber/ArticlePageSubscriberTest.php | 1 + .../Subscriber/ArticleSubscriberTest.php | 108 ++++++++++++++++++ .../Subscriber/PageSubscriberTest.php | 7 +- .../Subscriber/RoutableSubscriberTest.php | 12 +- 12 files changed, 210 insertions(+), 34 deletions(-) diff --git a/Controller/ArticlePageController.php b/Controller/ArticlePageController.php index b0617cbfa..a3d31d129 100644 --- a/Controller/ArticlePageController.php +++ b/Controller/ArticlePageController.php @@ -208,11 +208,6 @@ public function deleteAction($articleUuid, $uuid, Request $request) $documentManager->remove($document); $documentManager->flush(); - // FIXME this is a current hack which publishes article automatically when removing a single page - $document = $documentManager->find($articleUuid, $locale); - $documentManager->publish($document, $locale); - $documentManager->flush(); - return $this->handleView($this->view(null)); } diff --git a/Document/Behavior/PageBehavior.php b/Document/Behavior/PageBehavior.php index 7035c18f1..d88c27459 100644 --- a/Document/Behavior/PageBehavior.php +++ b/Document/Behavior/PageBehavior.php @@ -12,12 +12,13 @@ namespace Sulu\Bundle\ArticleBundle\Document\Behavior; use Sulu\Component\DocumentManager\Behavior\Mapping\ParentBehavior; +use Sulu\Component\DocumentManager\Behavior\Mapping\PathBehavior; use Sulu\Component\DocumentManager\Behavior\Mapping\UuidBehavior; /** * This behavior has to be attached to documents which should have a page-number property. */ -interface PageBehavior extends ParentBehavior, UuidBehavior +interface PageBehavior extends ParentBehavior, UuidBehavior, PathBehavior { /** * Returns page-number. diff --git a/Document/Subscriber/ArticlePageSubscriber.php b/Document/Subscriber/ArticlePageSubscriber.php index cdd63effe..2ba2812b0 100644 --- a/Document/Subscriber/ArticlePageSubscriber.php +++ b/Document/Subscriber/ArticlePageSubscriber.php @@ -21,6 +21,7 @@ use Sulu\Component\DocumentManager\DocumentManagerInterface; use Sulu\Component\DocumentManager\Event\MetadataLoadEvent; use Sulu\Component\DocumentManager\Event\PersistEvent; +use Sulu\Component\DocumentManager\Event\RemoveEvent; use Sulu\Component\DocumentManager\Events; use Sulu\Component\DocumentManager\NameResolver; use Symfony\Cmf\Api\Slugifier\SlugifierInterface; @@ -93,6 +94,7 @@ public static function getSubscribedEvents() ['setStructureTypeToParent', -2000], ['setWorkflowStageOnArticle', -2000], ], + Events::REMOVE => ['setWorkflowStageOnArticle'], Events::METADATA_LOAD => ['handleMetadataLoad'], ]; } @@ -115,9 +117,9 @@ public function setTitleOnPersist(PersistEvent $event) /** * Set workflow-stage to test for article. * - * @param PersistEvent $event + * @param PersistEvent|RemoveEvent $event */ - public function setWorkflowStageOnArticle(PersistEvent $event) + public function setWorkflowStageOnArticle($event) { $document = $event->getDocument(); if (!$document instanceof ArticlePageDocument @@ -127,7 +129,11 @@ public function setWorkflowStageOnArticle(PersistEvent $event) } $document->getParent()->setWorkflowStage(WorkflowStage::TEST); - $this->documentManager->persist($document->getParent(), $event->getLocale(), $event->getOptions()); + $this->documentManager->persist( + $document->getParent(), + $this->documentInspector->getLocale($document), + $event instanceof PersistEvent ? $event->getOptions() : [] + ); } /** @@ -238,7 +244,7 @@ public function setStructureTypeToParent(PersistEvent $event) } /** - * Add page-title to metadata. + * Extend metadata for article-page. * * @param MetadataLoadEvent $event */ @@ -248,7 +254,9 @@ public function handleMetadataLoad(MetadataLoadEvent $event) return; } - $event->getMetadata()->addFieldMapping( + $metadata = $event->getMetadata(); + $metadata->setSyncRemoveLive(false); + $metadata->addFieldMapping( 'pageTitle', [ 'encoding' => 'system_localized', diff --git a/Document/Subscriber/ArticleSubscriber.php b/Document/Subscriber/ArticleSubscriber.php index 9f70df193..89c7f1745 100644 --- a/Document/Subscriber/ArticleSubscriber.php +++ b/Document/Subscriber/ArticleSubscriber.php @@ -11,6 +11,7 @@ namespace Sulu\Bundle\ArticleBundle\Document\Subscriber; +use PHPCR\NodeInterface; use Sulu\Bundle\ArticleBundle\Document\ArticleDocument; use Sulu\Bundle\ArticleBundle\Document\ArticlePageDocument; use Sulu\Bundle\ArticleBundle\Document\Index\IndexerInterface; @@ -115,6 +116,7 @@ public static function getSubscribedEvents() Events::PUBLISH => [ ['handleScheduleIndexLive', 0], ['handleScheduleIndex', 0], + ['synchronizeChildren', 0], ['publishChildren', 0], ['persistPageData', -2000], ], @@ -168,6 +170,47 @@ public function handleScheduleIndexLive(AbstractMappingEvent $event) ]; } + /** + * Syncs children between live and draft. + * + * @param PublishEvent $event + */ + public function synchronizeChildren(PublishEvent $event) + { + $document = $event->getDocument(); + if (!$document instanceof ArticleDocument) { + return; + } + + $liveNode = $event->getNode(); + $draftNode = $this->documentInspector->getNode($document); + + $liveChildren = $this->getChildren($liveNode); + $draftChildren = $this->getChildren($draftNode); + $removedChildrenIds = array_diff(array_keys($liveChildren), array_keys($draftChildren)); + + foreach ($removedChildrenIds as $removedChildrenId) { + $liveChildren[$removedChildrenId]->remove(); + } + } + + /** + * Returns children of given node. + * + * @param NodeInterface $node + * + * @return NodeInterface[] + */ + private function getChildren(NodeInterface $node) + { + $result = []; + foreach ($node->getNodes() as $child) { + $result[$child->getIdentifier()] = $child; + } + + return $result; + } + /** * Publish pages when article will be published. * diff --git a/Document/Subscriber/PageSubscriber.php b/Document/Subscriber/PageSubscriber.php index c6a311b99..60257a472 100644 --- a/Document/Subscriber/PageSubscriber.php +++ b/Document/Subscriber/PageSubscriber.php @@ -56,8 +56,8 @@ public static function getSubscribedEvents() return [ Events::HYDRATE => ['handleHydrate'], Events::PERSIST => [['handlePersist', -1024]], - Events::PUBLISH => [['handlePublish', -1024]], Events::REMOVE => [['handleRemove', 5]], + Events::PUBLISH => [['handlePublishPageNumber', -1024]], ]; } @@ -117,7 +117,7 @@ public function handlePersist(PersistEvent $event) * * @param PublishEvent $event */ - public function handlePublish(PublishEvent $event) + public function handlePublishPageNumber(PublishEvent $event) { $document = $event->getDocument(); $node = $event->getNode(); @@ -141,10 +141,8 @@ public function handleRemove(RemoveEvent $event) return; } - $parentDocument = $document->getParent(); - $page = 1; - foreach ($parentDocument->getChildren() as $child) { + foreach ($document->getParent()->getChildren() as $child) { if (!$child instanceof PageBehavior || $child->getUuid() === $document->getUuid()) { continue; } diff --git a/Document/Subscriber/RoutableSubscriber.php b/Document/Subscriber/RoutableSubscriber.php index c44bd2019..c829aaea0 100644 --- a/Document/Subscriber/RoutableSubscriber.php +++ b/Document/Subscriber/RoutableSubscriber.php @@ -43,7 +43,7 @@ class RoutableSubscriber implements EventSubscriberInterface /** * @var ChainRouteGeneratorInterface */ - private $routeGeneratorPool; + private $chainRouteGenerator; /** * @var RouteManagerInterface @@ -76,7 +76,7 @@ class RoutableSubscriber implements EventSubscriberInterface private $documentInspector; /** - * @param ChainRouteGeneratorInterface $routeGeneratorPool + * @param ChainRouteGeneratorInterface $chainRouteGenerator * @param RouteManagerInterface $routeManager * @param RouteRepositoryInterface $routeRepository * @param EntityManagerInterface $entityManager @@ -85,7 +85,7 @@ class RoutableSubscriber implements EventSubscriberInterface * @param DocumentInspector $documentInspector */ public function __construct( - ChainRouteGeneratorInterface $routeGeneratorPool, + ChainRouteGeneratorInterface $chainRouteGenerator, RouteManagerInterface $routeManager, RouteRepositoryInterface $routeRepository, EntityManagerInterface $entityManager, @@ -93,7 +93,7 @@ public function __construct( StructureMetadataFactoryInterface $metadataFactory, DocumentInspector $documentInspector ) { - $this->routeGeneratorPool = $routeGeneratorPool; + $this->chainRouteGenerator = $chainRouteGenerator; $this->routeManager = $routeManager; $this->routeRepository = $routeRepository; $this->entityManager = $entityManager; @@ -158,7 +158,7 @@ public function handlePersist(AbstractMappingEvent $event) $document->setUuid($event->getNode()->getIdentifier()); - $generatedRoute = $this->routeGeneratorPool->generate( + $generatedRoute = $this->chainRouteGenerator->generate( $document, $event->getOption('route_path') ?: $document->getRoutePath() ); @@ -208,7 +208,27 @@ public function handlePublish(PublishEvent $event) * * @return RouteInterface */ - private function createOrUpdateRoute(RoutablePageBehavior $document, $locale) + private function createOrUpdatePageRoute(RoutablePageBehavior $document, $locale) + { + $route = $this->routeRepository->findByEntity($document->getClass(), $document->getUuid(), $locale); + if ($route) { + $document->setRoute($route); + + return $this->routeManager->update($document); + } + + return $this->routeManager->create($document); + } + + /** + * Create or update for given document. + * + * @param RoutableBehavior $document + * @param string $locale + * + * @return RouteInterface + */ + private function createOrUpdateRoute(RoutableBehavior $document, $locale) { $route = $this->routeRepository->findByEntity($document->getClass(), $document->getUuid(), $locale); if ($route) { @@ -231,7 +251,7 @@ private function removeOldChildRoutes(SessionInterface $session, array $oldRoute { foreach ($oldRoutes as $oldRoute) { $oldRouteEntity = $this->routeRepository->findByPath($oldRoute, $locale); - if (!$this->nodeExists($session, $oldRouteEntity->getEntityId())) { + if ($oldRouteEntity && !$this->nodeExists($session, $oldRouteEntity->getEntityId())) { $this->entityManager->remove($oldRouteEntity); } } @@ -255,7 +275,7 @@ private function generateChildRoutes(ChildrenBehavior $document, $locale) continue; } - $childRoute = $this->createOrUpdateRoute($child, $locale); + $childRoute = $this->createOrUpdatePageRoute($child, $locale); $this->entityManager->persist($childRoute); $child->setRoutePath($childRoute->getPath()); diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 976c1c4fc..095d6a63a 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -123,6 +123,7 @@ class="Sulu\Bundle\ArticleBundle\Document\Subscriber\PageSubscriber"> + diff --git a/Resources/translations/sulu/backend.de.xlf b/Resources/translations/sulu/backend.de.xlf index 668b76e44..c5c14196c 100644 --- a/Resources/translations/sulu/backend.de.xlf +++ b/Resources/translations/sulu/backend.de.xlf @@ -144,7 +144,7 @@ sulu_article.edit.new-page - Neue Seite erstellen + Seite hinzufügen diff --git a/Tests/Unit/Document/Subscriber/ArticlePageSubscriberTest.php b/Tests/Unit/Document/Subscriber/ArticlePageSubscriberTest.php index 1f3b01df1..4a740bafb 100644 --- a/Tests/Unit/Document/Subscriber/ArticlePageSubscriberTest.php +++ b/Tests/Unit/Document/Subscriber/ArticlePageSubscriberTest.php @@ -156,6 +156,7 @@ public function testSetWorkflowStageOnArticle() $this->document->getParent()->willReturn($this->parentDocument->reveal()); $this->documentInspector->getLocalizationState($this->parentDocument->reveal())->willReturn(LocalizationState::LOCALIZED); + $this->documentInspector->getLocale($this->document->reveal())->willReturn($this->locale); $this->parentDocument->setWorkflowStage(WorkflowStage::TEST)->shouldBeCalled(); $this->documentManager->persist($this->parentDocument->reveal(), $this->locale, Argument::any())->shouldBeCalled(); diff --git a/Tests/Unit/Document/Subscriber/ArticleSubscriberTest.php b/Tests/Unit/Document/Subscriber/ArticleSubscriberTest.php index 8cf47ffc4..c89c29f28 100644 --- a/Tests/Unit/Document/Subscriber/ArticleSubscriberTest.php +++ b/Tests/Unit/Document/Subscriber/ArticleSubscriberTest.php @@ -209,6 +209,114 @@ public function testPublishChildren() $this->articleSubscriber->publishChildren($this->prophesizeEvent(PublishEvent::class, $this->locale)); } + public function testSynchronizeChildren() + { + $document = $this->prophesize(ArticleDocument::class); + $liveNode = $this->prophesize(NodeInterface::class); + $draftNode = $this->prophesize(NodeInterface::class); + + $event = $this->prophesize(PublishEvent::class); + $event->getDocument()->willReturn($document->reveal()); + $event->getNode()->willReturn($liveNode->reveal()); + + $this->documentInspector->getNode($document->reveal())->willReturn($draftNode->reveal()); + + $children = [ + $this->createNodeMock('123-123-123'), + $this->createNodeMock('456-456-456'), + ]; + + $liveNode->getNodes()->willReturn($children); + $draftNode->getNodes()->willReturn($children); + + $this->articleSubscriber->synchronizeChildren($event->reveal()); + } + + public function testSynchronizeChildrenDifferenceRemove() + { + $document = $this->prophesize(ArticleDocument::class); + $liveNode = $this->prophesize(NodeInterface::class); + $draftNode = $this->prophesize(NodeInterface::class); + + $event = $this->prophesize(PublishEvent::class); + $event->getDocument()->willReturn($document->reveal()); + $event->getNode()->willReturn($liveNode->reveal()); + + $this->documentInspector->getNode($document->reveal())->willReturn($draftNode->reveal()); + + $children = [ + $this->createNodeMock('123-123-123'), + $this->createNodeMock('456-456-456', true), + ]; + + $liveNode->getNodes()->willReturn($children); + $draftNode->getNodes()->willReturn([$children[0]]); + + $this->articleSubscriber->synchronizeChildren($event->reveal()); + } + + public function testSynchronizeChildrenDifferenceAdd() + { + $document = $this->prophesize(ArticleDocument::class); + $liveNode = $this->prophesize(NodeInterface::class); + $draftNode = $this->prophesize(NodeInterface::class); + + $event = $this->prophesize(PublishEvent::class); + $event->getDocument()->willReturn($document->reveal()); + $event->getNode()->willReturn($liveNode->reveal()); + + $this->documentInspector->getNode($document->reveal())->willReturn($draftNode->reveal()); + + $children = [ + $this->createNodeMock('123-123-123'), + $this->createNodeMock('456-456-456'), + ]; + + $liveNode->getNodes()->willReturn([$children[0]]); + $draftNode->getNodes()->willReturn($children); + + // nothing should happen because publish new children will be done somewhere else + + $this->articleSubscriber->synchronizeChildren($event->reveal()); + } + + public function testSynchronizeChildrenDifferenceAddAndRemove() + { + $document = $this->prophesize(ArticleDocument::class); + $liveNode = $this->prophesize(NodeInterface::class); + $draftNode = $this->prophesize(NodeInterface::class); + + $event = $this->prophesize(PublishEvent::class); + $event->getDocument()->willReturn($document->reveal()); + $event->getNode()->willReturn($liveNode->reveal()); + + $this->documentInspector->getNode($document->reveal())->willReturn($draftNode->reveal()); + + $children = [ + $this->createNodeMock('123-123-123', true), + $this->createNodeMock('456-456-456'), + ]; + + $liveNode->getNodes()->willReturn([$children[0]]); + $draftNode->getNodes()->willReturn([$children[1]]); + + $this->articleSubscriber->synchronizeChildren($event->reveal()); + } + + private function createNodeMock($uuid, $removeCall = false) + { + $node = $this->prophesize(NodeInterface::class); + $node->getIdentifier()->willReturn($uuid); + + if ($removeCall) { + $node->remove()->shouldBeCalled(); + } else { + $node->remove()->shouldNotBeCalled(); + } + + return $node->reveal(); + } + public function testRemoveDraftChildren() { $children = [ diff --git a/Tests/Unit/Document/Subscriber/PageSubscriberTest.php b/Tests/Unit/Document/Subscriber/PageSubscriberTest.php index 017c995b9..5676faf75 100644 --- a/Tests/Unit/Document/Subscriber/PageSubscriberTest.php +++ b/Tests/Unit/Document/Subscriber/PageSubscriberTest.php @@ -60,7 +60,8 @@ protected function setUp() $this->node = $this->prophesize(NodeInterface::class); $this->pageSubscriber = new PageSubscriber( - $this->documentInspector->reveal(), $this->propertyEncoder->reveal() + $this->documentInspector->reveal(), + $this->propertyEncoder->reveal() ); } @@ -134,7 +135,7 @@ public function testHandleRemove() $this->pageSubscriber->handleRemove($event->reveal()); } - public function testHandlePublish() + public function testHandlePublishPageNumber() { $event = $this->prophesize(PublishEvent::class); $event->getDocument()->willReturn($this->document->reveal()); @@ -145,6 +146,6 @@ public function testHandlePublish() $this->document->getPageNumber()->willReturn(1); $this->node->setProperty('sulu:' . PageSubscriber::FIELD, 1)->shouldBeCalled(); - $this->pageSubscriber->handlePublish($event->reveal()); + $this->pageSubscriber->handlePublishPageNumber($event->reveal()); } } diff --git a/Tests/Unit/Document/Subscriber/RoutableSubscriberTest.php b/Tests/Unit/Document/Subscriber/RoutableSubscriberTest.php index ef2556c3d..c42b4b8ad 100644 --- a/Tests/Unit/Document/Subscriber/RoutableSubscriberTest.php +++ b/Tests/Unit/Document/Subscriber/RoutableSubscriberTest.php @@ -37,7 +37,7 @@ class RoutableSubscriberTest extends \PHPUnit_Framework_TestCase /** * @var ChainRouteGeneratorInterface */ - private $routeGeneratorPool; + private $chainGenerator; /** * @var RouteManagerInterface @@ -86,7 +86,7 @@ class RoutableSubscriberTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->routeGeneratorPool = $this->prophesize(ChainRouteGeneratorInterface::class); + $this->chainGenerator = $this->prophesize(ChainRouteGeneratorInterface::class); $this->routeManager = $this->prophesize(RouteManagerInterface::class); $this->routeRepository = $this->prophesize(RouteRepositoryInterface::class); $this->entityManager = $this->prophesize(EntityManagerInterface::class); @@ -100,7 +100,7 @@ protected function setUp() $this->node->getIdentifier()->willReturn('123-123-123'); $this->routableSubscriber = new RoutableSubscriber( - $this->routeGeneratorPool->reveal(), + $this->chainGenerator->reveal(), $this->routeManager->reveal(), $this->routeRepository->reveal(), $this->entityManager->reveal(), @@ -190,7 +190,7 @@ public function testHandlePersist() $metadata->hasTag(RoutableSubscriber::TAG_NAME)->willReturn(false); $this->metadataFactory->getStructureMetadata('article', 'default')->willReturn($metadata->reveal()); - $this->routeGeneratorPool->generate($this->document->reveal(), null) + $this->chainGenerator->generate($this->document->reveal(), null) ->willReturn(new Route('/test', null, get_class($this->document->reveal()))); $this->propertyEncoder->localizedSystemName(RoutableSubscriber::ROUTE_FIELD, 'de') @@ -215,7 +215,7 @@ public function testHandlePersistWithRoute() $metadata->hasTag(RoutableSubscriber::TAG_NAME)->willReturn(false); $this->metadataFactory->getStructureMetadata('article', 'default')->willReturn($metadata->reveal()); - $this->routeGeneratorPool->generate($this->document->reveal(), '/test-1') + $this->chainGenerator->generate($this->document->reveal(), '/test-1') ->willReturn(new Route('/test-1', null, get_class($this->document->reveal()))); $this->propertyEncoder->localizedSystemName(RoutableSubscriber::ROUTE_FIELD, 'de') @@ -240,7 +240,7 @@ public function testHandlePersistUpdate() $metadata->hasTag(RoutableSubscriber::TAG_NAME)->willReturn(false); $this->metadataFactory->getStructureMetadata('article', 'default')->willReturn($metadata->reveal()); - $this->routeGeneratorPool->generate($this->document->reveal(), '/test-2') + $this->chainGenerator->generate($this->document->reveal(), '/test-2') ->willReturn(new Route('/test-2', null, get_class($this->document->reveal()))); $this->propertyEncoder->localizedSystemName(RoutableSubscriber::ROUTE_FIELD, 'de') From 27f39b9781d59b75206a4febae920debd535b4d0 Mon Sep 17 00:00:00 2001 From: Johannes Wachter Date: Fri, 14 Apr 2017 10:22:17 +0200 Subject: [PATCH 2/2] fixed preview for new pages --- .../dist/components/articles/edit/adapter/article-page.js | 2 +- .../js/components/articles/edit/adapter/article-page.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Resources/public/dist/components/articles/edit/adapter/article-page.js b/Resources/public/dist/components/articles/edit/adapter/article-page.js index 5ddcc4382..5fa141c52 100644 --- a/Resources/public/dist/components/articles/edit/adapter/article-page.js +++ b/Resources/public/dist/components/articles/edit/adapter/article-page.js @@ -1 +1 @@ -define(["underscore","services/suluarticle/article-manager","services/sulupreview/preview"],function(a,b,c){"use strict";var d=function(a,b){return!a||!b._embedded||b._embedded.pages.length<=a-2?{}:b._embedded.pages[a-2]};return{getCopyLocaleUrl:function(a,c,d,e){return b.getCopyPageLocaleUrl(a,c,d,e)},startPreview:function(a,b){var e=d(a.options.page,b);e.type&&"ghost"===e.type.name&&(e={id:e.id});var f=c.initialize({});return f.start("Sulu\\Bundle\\ArticleBundle\\Document\\ArticlePageDocument",e.id,a.options.locale,e),f},destroyPreview:function(a){c.destroy(a)},beforeFormCreate:function(a){var b=a.getTitleProperty(),c=a.getRoutePathProperty();b&&b.$el.closest(".grid-row").remove(),c&&c.$el.closest(".grid-row").remove();var d=a.$el.find(".section-highlight");0===a.$el.find(".highlight-section *[data-mapper-property]").length&&(a.$el.find(".highlight-section").remove(),d=a.$el.find("#content-form")),d.prepend('

'+a.data.title+"

")},prepareData:function(a,b){return d(b.options.page,a)},save:function(a,c,d){var e=null,f=a.options.page-2;return a.data._embedded.pages[f]&&(e=a.data._embedded.pages[f].id),c.template=a.template,b.savePage(c,a.data.id,e,a.options.locale,d).then(function(){return b.loadSync(a.data.id,a.options.locale).responseJSON})}}}); \ No newline at end of file +define(["underscore","services/suluarticle/article-manager","services/sulupreview/preview"],function(a,b,c){"use strict";var d=function(a,b){return!a||!b._embedded||b._embedded.pages.length<=a-2?{}:b._embedded.pages[a-2]};return{getCopyLocaleUrl:function(a,c,d,e){return b.getCopyPageLocaleUrl(a,c,d,e)},startPreview:function(a,b){var e=d(a.options.page,b);if(e.id){e.type&&"ghost"===e.type.name&&(e={id:e.id});var f=c.initialize({});return f.start("Sulu\\Bundle\\ArticleBundle\\Document\\ArticlePageDocument",e.id,a.options.locale,e),f}},destroyPreview:function(a){c.destroy(a)},beforeFormCreate:function(a){var b=a.getTitleProperty(),c=a.getRoutePathProperty();b&&b.$el.closest(".grid-row").remove(),c&&c.$el.closest(".grid-row").remove();var d=a.$el.find(".section-highlight");0===a.$el.find(".highlight-section *[data-mapper-property]").length&&(a.$el.find(".highlight-section").remove(),d=a.$el.find("#content-form")),d.prepend('

'+a.data.title+"

")},prepareData:function(a,b){return d(b.options.page,a)},save:function(a,c,d){var e=null,f=a.options.page-2;return a.data._embedded.pages[f]&&(e=a.data._embedded.pages[f].id),c.template=a.template,b.savePage(c,a.data.id,e,a.options.locale,d).then(function(){return b.loadSync(a.data.id,a.options.locale).responseJSON})}}}); \ No newline at end of file diff --git a/Resources/public/js/components/articles/edit/adapter/article-page.js b/Resources/public/js/components/articles/edit/adapter/article-page.js index f8d327ceb..5c1368b06 100644 --- a/Resources/public/js/components/articles/edit/adapter/article-page.js +++ b/Resources/public/js/components/articles/edit/adapter/article-page.js @@ -30,6 +30,10 @@ define([ startPreview: function(component, data) { var pageData = getPage(component.options.page, data); + if (!pageData.id) { + return; + } + if (!!pageData.type && pageData.type.name === 'ghost') { pageData = {id: pageData.id}; }