-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added teaser-provider * introduced fallbacks for media and description
- Loading branch information
1 parent
99c048e
commit 6c9938f
Showing
14 changed files
with
424 additions
and
2 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
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,84 @@ | ||
<?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\EventListener; | ||
|
||
use JMS\Serializer\EventDispatcher\Events; | ||
use JMS\Serializer\EventDispatcher\EventSubscriberInterface; | ||
use JMS\Serializer\EventDispatcher\ObjectEvent; | ||
use Sulu\Bundle\ArticleBundle\Document\ArticleOngrDocument; | ||
|
||
/** | ||
* Append type translation to serialized article-ongr document. | ||
*/ | ||
class ArticleOngrDocumentSerializeSubscriber implements EventSubscriberInterface | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $typeConfiguration; | ||
|
||
/** | ||
* @param array $typeConfiguration | ||
*/ | ||
public function __construct(array $typeConfiguration) | ||
{ | ||
$this->typeConfiguration = $typeConfiguration; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function getSubscribedEvents() | ||
{ | ||
return [ | ||
[ | ||
'event' => Events::POST_SERIALIZE, | ||
'format' => 'json', | ||
'method' => 'onPostSerialize', | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* Add translated type. | ||
* | ||
* @param ObjectEvent $event | ||
*/ | ||
public function onPostSerialize(ObjectEvent $event) | ||
{ | ||
$article = $event->getObject(); | ||
$visitor = $event->getVisitor(); | ||
$context = $event->getContext(); | ||
|
||
if (!($article instanceof ArticleOngrDocument)) { | ||
return; | ||
} | ||
|
||
$visitor->addData('typeTranslation', $context->accept($this->getTitle($article->getType()))); | ||
} | ||
|
||
/** | ||
* Returns title for given type. | ||
* | ||
* @param string $type | ||
* | ||
* @return string | ||
*/ | ||
private function getTitle($type) | ||
{ | ||
if (!array_key_exists($type, $this->typeConfiguration)) { | ||
return ucfirst($type); | ||
} | ||
|
||
return $this->typeConfiguration[$type]['translation_key']; | ||
} | ||
} |
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
Oops, something went wrong.