Content-Length: 604128 | pFad | http://github.com/sulu/SuluArticleBundle/commit/6c9938faceaa485f47a15bb9a5cf6961b4ac43a1

42 Added teaser-provider (#11) · sulu/SuluArticleBundle@6c9938f · GitHub
Skip to content

Commit

Permalink
Added teaser-provider (#11)
Browse files Browse the repository at this point in the history
* added teaser-provider

* introduced fallbacks for media and description
  • Loading branch information
wachterjohannes authored and chirimoya committed Aug 18, 2016
1 parent 99c048e commit 6c9938f
Show file tree
Hide file tree
Showing 14 changed files with 424 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ matrix:
- php: 7.0

before_install:
- phpenv config-add Tests/travis.php.ini
- composer self-update

install:
Expand All @@ -23,6 +24,8 @@ install:
- ./Tests/app/console doctrine:database:create
- ./Tests/app/console doctrine:schema:update --force
- ./Tests/app/console sulu:document:initialize
- ./Tests/app/console ongr:es:index:create -m default
- ./Tests/app/console ongr:es:index:create -m live

script:
- ./vendor/bin/phpunit
4 changes: 3 additions & 1 deletion Controller/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ public function cgetAction(Request $request)
}
}

$search->addQuery(new TermQuery('type', $request->get('type', 'default')));
if (null !== ($type = $request->get('type'))) {
$search->addQuery(new TermQuery('type', $type));
}

$count = $repository->count($search);

Expand Down
87 changes: 87 additions & 0 deletions Document/ArticleOngrDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ class ArticleOngrDocument
*/
protected $title;

/**
* @var string
*
* @Property(type="string")
*/
protected $routePath;

/**
* @var string
*
Expand Down Expand Up @@ -107,6 +114,20 @@ class ArticleOngrDocument
*/
protected $authors;

/**
* @var string
*
* @Property(type="string")
*/
protected $teaserDescription = '';

/**
* @var int
*
* @Property(type="integer")
*/
protected $teaserMediaId;

/**
* @param string $uuid
*/
Expand Down Expand Up @@ -187,6 +208,26 @@ public function setTitle($title)
return $this;
}

/**
* Returns route-path.
*
* @return string
*/
public function getRoutePath()
{
return $this->routePath;
}

/**
* Set route-path.
*
* @param string $routePath
*/
public function setRoutePath($routePath)
{
$this->routePath = $routePath;
}

/**
* Returns type.
*
Expand Down Expand Up @@ -402,4 +443,50 @@ public function setAuthors($authors)

return $this;
}

/**
* Returns teaser-description.
*
* @return string
*/
public function getTeaserDescription()
{
return $this->teaserDescription;
}

/**
* Set teaser-description.
*
* @param string $teaserDescription
*
* @return $this
*/
public function setTeaserDescription($teaserDescription)
{
$this->teaserDescription = $teaserDescription;

return $this;
}

/**
* Returns teaser-media-id.
*
* @return int
*/
public function getTeaserMediaId()
{
return $this->teaserMediaId;
}

/**
* Set teaser-media-id.
*
* @param int $teaserMediaId
*
* @return int
*/
public function setTeaserMediaId($teaserMediaId)
{
$this->teaserMediaId = $teaserMediaId;
}
}
15 changes: 15 additions & 0 deletions Document/Index/ArticleIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public function index(ArticleDocument $document)
$structure = $this->structureManager->getStructure($document->getStructureType(), 'article');

$article->setTitle($document->getTitle());
$article->setRoutePath($document->getRoutePath());
$article->setChanged($document->getChanged());
$article->setCreated($document->getCreated());
$article->setAuthored($document->getAuthored());
Expand All @@ -99,6 +100,20 @@ public function index(ArticleDocument $document)
$article->setExcerpt($this->createExcerptObject($extensions['excerpt']));
$article->setSeo($this->createSeoObject($extensions['seo']));

if ($structure->hasTag('sulu.teaser.description')) {
$descriptionProperty = $structure->getPropertyByTagName('sulu.teaser.description');
$article->setTeaserDescription(
$document->getStructure()->getProperty($descriptionProperty->getName())->getValue()
);
}
if ($structure->hasTag('sulu.teaser.media')) {
$mediaProperty = $structure->getPropertyByTagName('sulu.teaser.media');
$mediaData = $document->getStructure()->getProperty($mediaProperty->getName())->getValue();
if (null !== $mediaData && array_key_exists('ids', $mediaData)) {
$article->setTeaserMediaId(reset($mediaData['ids']) ?: null);
}
}

$this->manager->persist($article);
}

Expand Down
2 changes: 1 addition & 1 deletion Document/MediaCollectionOngrObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MediaCollectionOngrObject
*
* @Property(type="integer")
*/
public $ids;
public $ids = [];

/**
* @var string
Expand Down
84 changes: 84 additions & 0 deletions EventListener/ArticleOngrDocumentSerializeSubscriber.php
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'];
}
}
14 changes: 14 additions & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,19 @@

<tag name="sulu.smart_content.data_provider" alias="articles"/>
</service>
<service id="sulu_article.teaser.provider" class="Sulu\Bundle\ArticleBundle\Teaser\ArticleTeaserProvider">
<argument type="service" id="es.manager.live"/>

<tag name="sulu.teaser.provider" alias="article"/>
</service>

<!-- serialization -->
<service id="sulu_article.serializer.event_subscriber"
class="Sulu\Bundle\ArticleBundle\EventListener\ArticleOngrDocumentSerializeSubscriber">
<argument>%sulu_articles.types%</argument>

<tag name="jms_serializer.event_subscriber" />
<tag name="sulu.context" context="admin"/>
</service>
</services>
</container>
4 changes: 4 additions & 0 deletions Resources/translations/sulu/backend.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
<source>sulu_article.authors</source>
<target>Autoren</target>
</trans-unit>
<trans-unit id="9" resname="sulu_article.teaser">
<source>sulu_article.teaser</source>
<target>Artikel</target>
</trans-unit>
</body>
</file>
</xliff>
4 changes: 4 additions & 0 deletions Resources/translations/sulu/backend.en.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
<source>sulu_article.authors</source>
<target>Authors</target>
</trans-unit>
<trans-unit id="9" resname="sulu_article.teaser">
<source>sulu_article.teaser</source>
<target>Article</target>
</trans-unit>
</body>
</file>
</xliff>
4 changes: 4 additions & 0 deletions Resources/translations/sulu/backend.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
<source>sulu_article.authors</source>
<target>Auteur</target>
</trans-unit>
<trans-unit id="9" resname="sulu_article.teaser">
<source>sulu_article.teaser</source>
<target>Article</target>
</trans-unit>
</body>
</file>
</xliff>
Loading

0 comments on commit 6c9938f

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/sulu/SuluArticleBundle/commit/6c9938faceaa485f47a15bb9a5cf6961b4ac43a1

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy