Skip to content

Commit

Permalink
Add interface to manage article-pages (sulu#116)
Browse files Browse the repository at this point in the history
* introduced css grunt job

* added article-router

* added page dropdown

* added logic to create and update pages

* renamed adapter
  • Loading branch information
wachterjohannes committed Apr 25, 2017
1 parent 0d26e70 commit aa9f100
Show file tree
Hide file tree
Showing 47 changed files with 1,393 additions and 144 deletions.
2 changes: 1 addition & 1 deletion Controller/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public function postTriggerAction($uuid, Request $request)
}

// prepare view
$view = $this->view($data, $data !== null ? 200 : 204);
$view = $this->view($data);
$view->setSerializationContext(
SerializationContext::create()
->setSerializeNull(true)
Expand Down
54 changes: 50 additions & 4 deletions Controller/ArticlePageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Sulu\Bundle\ArticleBundle\Controller;

use FOS\RestBundle\Controller\Annotations\Post;
use FOS\RestBundle\Routing\ClassResourceInterface;
use JMS\Serializer\SerializationContext;
use Sulu\Bundle\ArticleBundle\Admin\ArticleAdmin;
Expand All @@ -22,6 +23,7 @@
use Sulu\Component\Content\Mapper\ContentMapperInterface;
use Sulu\Component\DocumentManager\DocumentManagerInterface;
use Sulu\Component\Rest\Exception\MissingParameterException;
use Sulu\Component\Rest\Exception\RestException;
use Sulu\Component\Rest\RequestParametersTrait;
use Sulu\Component\Rest\RestController;
use Sulu\Component\Security\SecuredControllerInterface;
Expand Down Expand Up @@ -104,6 +106,51 @@ public function postAction($articleUuid, Request $request)
);
}

/**
* Trigger a action for given article-page specified over get-action parameter.
*
* @Post("/articles/{articleUuid}/pages/{uuid}")
*
* @param string $uuid
* @param Request $request
*
* @return Response
*/
public function postTriggerAction($articleUuid, $uuid, Request $request)
{
// extract parameter
$action = $this->getRequestParameter($request, 'action', true);
$locale = $this->getRequestParameter($request, 'locale', true);

// prepare vars
$view = null;
$data = null;
$userId = $this->getUser()->getId();

try {
switch ($action) {
case 'copy-locale':
$destLocales = $this->getRequestParameter($request, 'dest', true);
$data = $this->getMapper()->copyLanguage($uuid, $userId, null, $locale, explode(',', $destLocales));
break;
default:
throw new RestException('Unrecognized action: ' . $action);
}

// prepare view
$view = $this->view($data);
$view->setSerializationContext(
SerializationContext::create()
->setSerializeNull(true)
->setGroups(['defaultPage', 'defaultArticlePage', 'smallArticle'])
);
} catch (RestException $exc) {
$view = $this->view($exc->toArray(), 400);
}

return $this->handleView($view);
}

/**
* Update article-page.
*
Expand Down Expand Up @@ -186,12 +233,11 @@ private function persistDocument($data, $document, $locale, $articleUuid)
if (array_key_exists('title', $data)) {
throw new ParameterNotAllowedException('title', ArticlePageDocument::class);
}
if (array_key_exists('template', $data)) {
throw new ParameterNotAllowedException('template', ArticlePageDocument::class);
}

$article = $this->getDocumentManager()->find($articleUuid, $locale);
$data['template'] = $article->getStructureType();
if (!array_key_exists('template', $data)) {
$data['template'] = $article->getStructureType();
}

$form = $this->createForm(
ArticlePageDocumentType::class,
Expand Down
6 changes: 3 additions & 3 deletions Controller/WebsiteArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
namespace Sulu\Bundle\ArticleBundle\Controller;

use JMS\Serializer\SerializationContext;
use Sulu\Bundle\ArticleBundle\Document\ArticleDocument;
use Sulu\Component\HttpCache\HttpCache;
use Sulu\Bundle\ArticleBundle\Document\ArticleInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -27,12 +27,12 @@ class WebsiteArticleController extends Controller
* Article index action.
*
* @param Request $request
* @param ArticleDocument $object
* @param ArticleInterface $object
* @param string $view
*
* @return Response
*/
public function indexAction(Request $request, ArticleDocument $object, $view)
public function indexAction(Request $request, ArticleInterface $object, $view)
{
$content = $this->get('jms_serializer')->serialize(
$object,
Expand Down
19 changes: 18 additions & 1 deletion Document/ArticleDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class ArticleDocument implements
WorkflowStageBehavior,
VersionBehavior,
AuthorBehavior,
ChildrenBehavior
ChildrenBehavior,
ArticleInterface
{
/**
* @var string
Expand Down Expand Up @@ -487,4 +488,20 @@ public function getChildren()
{
return $this->children;
}

/**
* {@inheritdoc}
*/
public function getArticleUuid()
{
return $this->getUuid();
}

/**
* {@inheritdoc}
*/
public function getPageUuid()
{
return $this->getUuid();
}
}
63 changes: 63 additions & 0 deletions Document/ArticleInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?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\Document;

use Sulu\Component\Content\Document\Extension\ExtensionContainer;
use Sulu\Component\Content\Document\Structure\StructureInterface;

/**
* This interface defines the intersection of article and article-page document.
*/
interface ArticleInterface
{
/**
* Returns article-uuid.
*
* @return string
*/
public function getArticleUuid();

/**
* Returns page-uuid.
*
* @return string
*/
public function getPageUuid();

/**
* Returns structure-type.
*
* @return string
*/
public function getStructureType();

/**
* Returns structure.
*
* @return StructureInterface
*/
public function getStructure();

/**
* Return the workflow stage.
*
* @return string|int
*/
public function getWorkflowStage();

/**
* Returns all extension data.
*
* @return ExtensionContainer
*/
public function getExtensionsData();
}
35 changes: 34 additions & 1 deletion Document/ArticlePageDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class ArticlePageDocument implements
ParentBehavior,
AutoNameBehavior,
PathBehavior,
StructureBehavior
StructureBehavior,
ArticleInterface
{
/**
* @var string
Expand Down Expand Up @@ -214,4 +215,36 @@ public function getPageNumber()
{
return $this->pageNumber;
}

/**
* {@inheritdoc}
*/
public function getArticleUuid()
{
return $this->getParent()->getUuid();
}

/**
* {@inheritdoc}
*/
public function getPageUuid()
{
return $this->getUuid();
}

/**
* {@inheritdoc}
*/
public function getWorkflowStage()
{
return $this->getParent()->getWorkflowStage();
}

/**
* {@inheritdoc}
*/
public function getExtensionsData()
{
return $this->getParent()->getExtensionsData();
}
}
11 changes: 7 additions & 4 deletions Document/Serializer/ArticleSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use ProxyManager\Factory\LazyLoadingValueHolderFactory;
use ProxyManager\Proxy\LazyLoadingInterface;
use Sulu\Bundle\ArticleBundle\Document\ArticleDocument;
use Sulu\Bundle\ArticleBundle\Document\ArticleInterface;
use Sulu\Bundle\ArticleBundle\Metadata\ArticleTypeTrait;
use Sulu\Component\Content\Compat\StructureManagerInterface;
use Sulu\Component\Content\ContentTypeManagerInterface;
Expand Down Expand Up @@ -107,11 +108,13 @@ public function resolveContentOnPostSerialize(ObjectEvent $event)
$visitor = $event->getVisitor();
$context = $event->getContext();

if (!$article instanceof ArticleDocument || !$context->attributes->containsKey('website')) {
if (!$article instanceof ArticleInterface || !$context->attributes->containsKey('website')) {
return;
}

$visitor->addData('uuid', $context->accept($article->getUuid()));
$visitor->addData('uuid', $context->accept($article->getArticleUuid()));
$visitor->addData('pageUuid', $context->accept($article->getPageUuid()));

$visitor->addData('extension', $context->accept($article->getExtensionsData()->toArray()));

$content = $this->resolve($article);
Expand All @@ -123,11 +126,11 @@ public function resolveContentOnPostSerialize(ObjectEvent $event)
/**
* Returns content and view of article.
*
* @param ArticleDocument $article
* @param ArticleInterface $article
*
* @return array
*/
private function resolve(ArticleDocument $article)
private function resolve(ArticleInterface $article)
{
$structure = $this->structureManager->getStructure($article->getStructureType(), 'article');
$structure->setDocument($article);
Expand Down
Loading

0 comments on commit aa9f100

Please sign in to comment.