for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?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\ArticlePageDocument;
/**
* Extends serialization for article-pages.
class ArticlePageSubscriber implements EventSubscriberInterface
{
* {@inheritdoc}
public static function getSubscribedEvents()
return [
[
'event' => Events::POST_SERIALIZE,
'format' => 'json',
'method' => 'addTitleOnPostSerialize',
],
];
}
* Append title to result.
* @param ObjectEvent $event
public function addTitleOnPostSerialize(ObjectEvent $event)
$articlePage = $event->getObject();
$visitor = $event->getVisitor();
$context = $event->getContext();
if (!$articlePage instanceof ArticlePageDocument) {
return;
$visitor->addData('title', $context->accept($articlePage->getParent()->getTitle()));