-
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.
- Loading branch information
1 parent
68ae0c1
commit 2d29ab7
Showing
26 changed files
with
560 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?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\Admin; | ||
|
||
use Sulu\Bundle\AdminBundle\Admin\JsConfigInterface; | ||
use Sulu\Bundle\ArticleBundle\Util\TypeTrait; | ||
use Sulu\Component\Content\Compat\StructureManagerInterface; | ||
|
||
/** | ||
* Provides js-configuration. | ||
*/ | ||
class ArticleJsConfig implements JsConfigInterface | ||
{ | ||
use TypeTrait; | ||
|
||
/** | ||
* @var StructureManagerInterface | ||
*/ | ||
private $structureManager; | ||
|
||
/** | ||
* @param StructureManagerInterface $structureManager | ||
*/ | ||
public function __construct(StructureManagerInterface $structureManager) | ||
{ | ||
$this->structureManager = $structureManager; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getParameters() | ||
{ | ||
$types = []; | ||
foreach ($this->structureManager->getStructures('article') as $structure) { | ||
$type = $this->getType($structure->getStructure()); | ||
if (!array_key_exists($type, $types)) { | ||
$types[$type] = $structure->getKey(); | ||
} | ||
} | ||
|
||
return $types; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() | ||
{ | ||
return 'sulu_article.types'; | ||
} | ||
} |
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,58 @@ | ||
<?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 Sulu\Bundle\ArticleBundle\Util\TypeTrait; | ||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
/** | ||
* Manages template for articles. | ||
*/ | ||
class TemplateController extends Controller | ||
{ | ||
use TypeTrait; | ||
|
||
/** | ||
* Returns template for given article type. | ||
* | ||
* @param Request $request | ||
* | ||
* @return JsonResponse | ||
*/ | ||
public function getAction(Request $request) | ||
{ | ||
$structureProvider = $this->get('sulu.content.structure_manager'); | ||
$type = $request->get('type', 'default'); | ||
|
||
$templates = []; | ||
foreach ($structureProvider->getStructures('article') as $structure) { | ||
if ($this->getType($structure->getStructure()) !== $type) { | ||
continue; | ||
} | ||
|
||
$templates[] = [ | ||
'internal' => $structure->getInternal(), | ||
'template' => $structure->getKey(), | ||
'title' => $structure->getLocalizedTitle($this->getUser()->getLocale()), | ||
]; | ||
} | ||
|
||
return new JsonResponse( | ||
[ | ||
'_embedded' => $templates, | ||
'total' => count($templates), | ||
] | ||
); | ||
} | ||
} |
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,73 @@ | ||
<?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\Serializer; | ||
|
||
use JMS\Serializer\EventDispatcher\Events; | ||
use JMS\Serializer\EventDispatcher\EventSubscriberInterface; | ||
use JMS\Serializer\EventDispatcher\ObjectEvent; | ||
use Sulu\Bundle\ArticleBundle\Document\ArticleDocument; | ||
use Sulu\Bundle\ArticleBundle\Util\TypeTrait; | ||
use Sulu\Component\Content\Compat\StructureManagerInterface; | ||
|
||
/** | ||
* Appends type to article-document. | ||
*/ | ||
class TypeSubscriber implements EventSubscriberInterface | ||
{ | ||
use TypeTrait; | ||
|
||
/** | ||
* @var StructureManagerInterface | ||
*/ | ||
private $structureManager; | ||
|
||
/** | ||
* @param StructureManagerInterface $structureManager | ||
*/ | ||
public function __construct(StructureManagerInterface $structureManager) | ||
{ | ||
$this->structureManager = $structureManager; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function getSubscribedEvents() | ||
{ | ||
return [ | ||
[ | ||
'event' => Events::POST_SERIALIZE, | ||
'format' => 'json', | ||
'method' => 'onPostSerialize', | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* Append type to result. | ||
* | ||
* @param ObjectEvent $event | ||
*/ | ||
public function onPostSerialize(ObjectEvent $event) | ||
{ | ||
$article = $event->getObject(); | ||
$visitor = $event->getVisitor(); | ||
$context = $event->getContext(); | ||
|
||
if (!($article instanceof ArticleDocument)) { | ||
return; | ||
} | ||
|
||
$structure = $this->structureManager->getStructure($article->getStructureType(), 'article'); | ||
$visitor->addData('type', $context->accept($this->getType($structure->getStructure()))); | ||
} | ||
} |
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,10 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<routes xmlns="http://symfony.com/schema/routing" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> | ||
|
||
<route id="sulu_article.templates" path="/templates"> | ||
<default key="_controller">SuluArticleBundle:Template:get</default> | ||
</route> | ||
|
||
</routes> |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.