-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented multipage articles (#122)
* Implemented page document and API (#114) * implemented basic page document * added index pages to article * fixed serialization context of article and article-page (#118) * Add interface to manage article-pages (#116) * introduced css grunt job * added article-router * added page dropdown * added logic to create and update pages * renamed adapter * Added article title to page form (#123) * added article title * fixed selector for css stye * fixed jquery selector of grid-row * added page to content-navigation (#125) * Fixed create article from ghost (#126) * fixed create article from ghost * hide new page link for new articls * fixed code style * added delete page button (#132) * added translations (#128) * added route-behavior to article-page (#131) * Fixed priorities of subscriber (#137) * fixed priorities of subscriber * added tag to find routePath property * Fixed title property (article-title) and add page title property (#141) * fixed title property (article-title) and add page title property * added node-name-slugifier * Changed generating route only on publish (#138) * use publish event to generate routes * refactored because of sulu changes * Added page-number argument to website-article-controller (#142) * added serialization of pages * added pages data to article-document * fixed comments * Added synchronize children between draft and live (#139) * added synchronice children between draft and live * fixed preview for new pages * fixed serialization for preview * fixed testcases * Fixed versioning and remove-draft of article-pages (#145) * fixed versioning of article-pages * added upgrade note * added constraint for jackalope/jackalope * implemented duplicate article (#146) * Fixed preview-serialization of article pages (#154) * fixed preview-serialization of article pages * change view of renderArticle * fixed type change on list (#156) * Fixed metadata for article to sync remove (#155) * fixed metadata for article * fixed routable-subscriber to remove all routes (locales) * removed article-page copy locale (#157) * fixed code-style * fixed test-setup
- Loading branch information
1 parent
4cd0e89
commit ff79b7f
Showing
94 changed files
with
5,773 additions
and
543 deletions.
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
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
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,259 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) MASSIVE ART WebServices GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Bundle\ArticleBundle\Controller; | ||
|
||
use FOS\RestBundle\Routing\ClassResourceInterface; | ||
use JMS\Serializer\SerializationContext; | ||
use Sulu\Bundle\ArticleBundle\Admin\ArticleAdmin; | ||
use Sulu\Bundle\ArticleBundle\Document\ArticlePageDocument; | ||
use Sulu\Bundle\ArticleBundle\Document\Form\ArticlePageDocumentType; | ||
use Sulu\Bundle\ArticleBundle\Exception\ArticlePageNotFoundException; | ||
use Sulu\Bundle\ArticleBundle\Exception\ParameterNotAllowedException; | ||
use Sulu\Component\Content\Form\Exception\InvalidFormException; | ||
use Sulu\Component\Content\Mapper\ContentMapperInterface; | ||
use Sulu\Component\DocumentManager\DocumentManagerInterface; | ||
use Sulu\Component\Rest\Exception\MissingParameterException; | ||
use Sulu\Component\Rest\RequestParametersTrait; | ||
use Sulu\Component\Rest\RestController; | ||
use Sulu\Component\Security\SecuredControllerInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
/** | ||
* Provides API for article-pages. | ||
*/ | ||
class ArticlePageController extends RestController implements ClassResourceInterface, SecuredControllerInterface | ||
{ | ||
const DOCUMENT_TYPE = 'article_page'; | ||
|
||
use RequestParametersTrait; | ||
|
||
/** | ||
* Returns single article-page. | ||
* | ||
* @param string $articleUuid | ||
* @param string $uuid | ||
* @param Request $request | ||
* | ||
* @return Response | ||
* | ||
* @throws ArticlePageNotFoundException | ||
*/ | ||
public function getAction($articleUuid, $uuid, Request $request) | ||
{ | ||
$locale = $this->getRequestParameter($request, 'locale', true); | ||
$document = $this->getDocumentManager()->find( | ||
$uuid, | ||
$locale, | ||
[ | ||
'load_ghost_content' => true, | ||
'load_shadow_content' => false, | ||
] | ||
); | ||
|
||
if ($articleUuid !== $document->getParent()->getUuid()) { | ||
// it is required that the parent will be called to resolve the proxy. | ||
// this wont be done in the serialization process. | ||
|
||
throw new ArticlePageNotFoundException($uuid, $articleUuid); | ||
} | ||
|
||
return $this->handleView( | ||
$this->view($document)->setSerializationContext( | ||
SerializationContext::create() | ||
->setSerializeNull(true) | ||
->setGroups(['defaultPage', 'defaultArticlePage', 'smallArticle']) | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Create article-page. | ||
* | ||
* @param string $articleUuid | ||
* @param Request $request | ||
* | ||
* @return Response | ||
*/ | ||
public function postAction($articleUuid, Request $request) | ||
{ | ||
$action = $request->get('action'); | ||
$document = $this->getDocumentManager()->create(self::DOCUMENT_TYPE); | ||
$locale = $this->getRequestParameter($request, 'locale', true); | ||
$data = $request->request->all(); | ||
|
||
$this->persistDocument($data, $document, $locale, $articleUuid); | ||
$this->handleActionParameter($action, $document->getParent(), $locale); | ||
$this->getDocumentManager()->flush(); | ||
|
||
return $this->handleView( | ||
$this->view($document)->setSerializationContext( | ||
SerializationContext::create() | ||
->setSerializeNull(true) | ||
->setGroups(['defaultPage', 'defaultArticlePage', 'smallArticle']) | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Update article-page. | ||
* | ||
* @param string $articleUuid | ||
* @param string $uuid | ||
* @param Request $request | ||
* | ||
* @return Response | ||
*/ | ||
public function putAction($articleUuid, $uuid, Request $request) | ||
{ | ||
$locale = $this->getRequestParameter($request, 'locale', true); | ||
$action = $request->get('action'); | ||
$data = $request->request->all(); | ||
|
||
$document = $this->getDocumentManager()->find( | ||
$uuid, | ||
$locale, | ||
[ | ||
'load_ghost_content' => false, | ||
'load_shadow_content' => false, | ||
] | ||
); | ||
|
||
$this->get('sulu_hash.request_hash_checker')->checkHash($request, $document, $document->getUuid()); | ||
|
||
$this->persistDocument($data, $document, $locale, $articleUuid); | ||
$this->handleActionParameter($action, $document->getParent(), $locale); | ||
$this->getDocumentManager()->flush(); | ||
|
||
return $this->handleView( | ||
$this->view($document)->setSerializationContext( | ||
SerializationContext::create() | ||
->setSerializeNull(true) | ||
->setGroups(['defaultPage', 'defaultArticlePage', 'smallArticle']) | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Delete article-page. | ||
* | ||
* @param string $articleUuid | ||
* @param string $uuid | ||
* @param Request $request | ||
* | ||
* @return Response | ||
*/ | ||
public function deleteAction($articleUuid, $uuid, Request $request) | ||
{ | ||
$locale = $this->getRequestParameter($request, 'locale', true); | ||
|
||
$documentManager = $this->getDocumentManager(); | ||
$document = $documentManager->find($uuid, $locale); | ||
$documentManager->remove($document); | ||
$documentManager->flush(); | ||
|
||
return $this->handleView($this->view(null)); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getSecurityContext() | ||
{ | ||
return ArticleAdmin::SECURITY_CONTEXT; | ||
} | ||
|
||
/** | ||
* Persists the document using the given information. | ||
* | ||
* @param array $data | ||
* @param object $document | ||
* @param string $locale | ||
* @param string $articleUuid | ||
* | ||
* @throws InvalidFormException | ||
* @throws MissingParameterException | ||
* @throws ParameterNotAllowedException | ||
*/ | ||
private function persistDocument($data, $document, $locale, $articleUuid) | ||
{ | ||
if (array_key_exists('title', $data)) { | ||
throw new ParameterNotAllowedException('title', ArticlePageDocument::class); | ||
} | ||
|
||
$article = $this->getDocumentManager()->find($articleUuid, $locale); | ||
if (!array_key_exists('template', $data)) { | ||
$data['template'] = $article->getStructureType(); | ||
} | ||
|
||
$form = $this->createForm( | ||
ArticlePageDocumentType::class, | ||
$document, | ||
[ | ||
// disable csrf protection, since we can't produce a token, because the form is cached on the client | ||
'csrf_protection' => false, | ||
] | ||
); | ||
$form->submit($data, false); | ||
|
||
$document->setParent($article); | ||
|
||
if (!$form->isValid()) { | ||
throw new InvalidFormException($form); | ||
} | ||
|
||
$this->getDocumentManager()->persist( | ||
$document, | ||
$locale, | ||
[ | ||
'user' => $this->getUser()->getId(), | ||
'clear_missing_content' => false, | ||
'auto_name' => false, | ||
'auto_rename' => false, | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Returns document-manager. | ||
* | ||
* @return DocumentManagerInterface | ||
*/ | ||
protected function getDocumentManager() | ||
{ | ||
return $this->get('sulu_document_manager.document_manager'); | ||
} | ||
|
||
/** | ||
* @return ContentMapperInterface | ||
*/ | ||
protected function getMapper() | ||
{ | ||
return $this->get('sulu.content.mapper'); | ||
} | ||
|
||
/** | ||
* Delegates actions by given actionParameter, which can be retrieved from the request. | ||
* | ||
* @param string $actionParameter | ||
* @param object $document | ||
* @param string $locale | ||
*/ | ||
private function handleActionParameter($actionParameter, $document, $locale) | ||
{ | ||
switch ($actionParameter) { | ||
case 'publish': | ||
$this->getDocumentManager()->publish($document, $locale); | ||
break; | ||
} | ||
} | ||
} |
Oops, something went wrong.