Skip to content

Commit

Permalink
Merge branch '2.0' of github.com:sulu/suluarticlebundle into 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Sep 11, 2020
2 parents 6b3d4d7 + 2fdda87 commit 8db3708
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 13 deletions.
2 changes: 0 additions & 2 deletions Admin/ArticleAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ function(Localization $localization) {
$this->viewBuilderFactory->createPreviewFormViewBuilder(static::EDIT_FORM_VIEW_EXCERPT . '_' . $typeKey, '/excerpt')
->setResourceKey('articles')
->setFormKey('page_excerpt')
->setBackView(static::LIST_VIEW)
->setTabTitle('sulu_page.excerpt')
->addToolbarActions($formToolbarActionsWithoutType)
->setParent(static::EDIT_FORM_VIEW . '_' . $typeKey)
Expand All @@ -285,7 +284,6 @@ function(Localization $localization) {
$this->viewBuilderFactory->createPreviewFormViewBuilder(static::EDIT_FORM_VIEW_SETTINGS . '_' . $typeKey, '/settings')
->setResourceKey('articles')
->setFormKey('article_settings')
->setBackView(static::LIST_VIEW)
->setTabTitle('sulu_page.settings')
->setTabPriority(512)
->addToolbarActions($formToolbarActionsWithoutType)
Expand Down
3 changes: 2 additions & 1 deletion Document/ArticleViewDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
/**
* Indexable document for articles.
*
* @Document(type="article")
* Following annotation will be set by the annotation reader if this document is used for mapping.
* Document(type="article")
*/
class ArticleViewDocument implements ArticleViewDocumentInterface
{
Expand Down
72 changes: 72 additions & 0 deletions Elasticsearch/AnnotationReader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

/*
* This file is part of Sulu.
*
* (c) Sulu 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\Elasticsearch;

use Doctrine\Common\Annotations\Reader;
use ONGR\ElasticsearchBundle\Annotation\Document;

class AnnotationReader implements Reader
{
/**
* @var Reader
*/
private $inner;

/**
* @var string
*/
private $articleViewDocumentClass;

public function __construct(Reader $inner, $articleViewDocumentClass)
{
$this->inner = $inner;
$this->articleViewDocumentClass = $articleViewDocumentClass;
}

public function getClassAnnotations(\ReflectionClass $class)
{
return $this->inner->getClassAnnotations($class);
}

public function getClassAnnotation(\ReflectionClass $class, $annotationName)
{
$result = $this->inner->getClassAnnotation($class, $annotationName);
if (!$result && Document::class === $annotationName && $class->getName() === $this->articleViewDocumentClass) {
$annotation = new Document();
$annotation->type = 'article';

return $annotation;
}

return $result;
}

public function getMethodAnnotations(\ReflectionMethod $method)
{
return $this->inner->getMethodAnnotations($method);
}

public function getMethodAnnotation(\ReflectionMethod $method, $annotationName)
{
return $this->inner->getMethodAnnotation($method, $annotationName);
}

public function getPropertyAnnotations(\ReflectionProperty $property)
{
return $this->inner->getPropertyAnnotations($property);
}

public function getPropertyAnnotation(\ReflectionProperty $property, $annotationName)
{
return $this->inner->getPropertyAnnotation($property, $annotationName);
}
}
9 changes: 8 additions & 1 deletion Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,6 @@
<tag name="massive_build.builder" />
</service>


<!-- webspace settings resolver -->
<service id="sulu_bundle_article.webspace_settings_configuration_resolver"
class="Sulu\Bundle\ArticleBundle\DependencyInjection\WebspaceSettingsConfigurationResolver">
Expand All @@ -454,5 +453,13 @@

<tag name="kernel.event_subscriber" />
</service>

<!-- annotation reader -->
<service id="sulu_article.annotations.cached_reader"
decorates="es.annotations.cached_reader"
class="Sulu\Bundle\ArticleBundle\Elasticsearch\AnnotationReader">
<argument type="service" id="sulu_article.annotations.cached_reader.inner"/>
<argument type="string">%sulu_article.view_document.article.class%</argument>
</service>
</services>
</container>
3 changes: 1 addition & 2 deletions Resources/doc/article-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ sulu_article:
translation_key: "app.article_types.my_article_type"
```
This key can the be used to translate the key with the
[Sulu translation system](http://docs.sulu.io/en/latest/developer/contributing/adding-translations.html).
This key can the be used to translate the key by adding a Translation File `translations/admin.en.json`.

## Usage in Content-Types

Expand Down
2 changes: 1 addition & 1 deletion Resources/doc/article-view-document.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use ONGR\ElasticsearchBundle\Annotation\Property;
use Sulu\Bundle\ArticleBundle\Document\ArticleViewDocument as SuluArticleViewDocument;

/**
* @Document(type="app_article")
* @Document(type="article")
*/
class ArticleViewDocument extends SuluArticleViewDocument
{
Expand Down
14 changes: 14 additions & 0 deletions Tests/Application/config/config_extend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,17 @@ sulu_route:
options:
route_schema: "/{translator.trans(\"page\")}-{object.getPageNumber()}"
parent: "{object.getParent().getRoutePath()}"

ongr_elasticsearch:
managers:
default:
mappings:
- TestExtendBundle
live:
mappings:
- TestExtendBundle

sulu_article:
documents:
article:
view: Sulu\Bundle\ArticleBundle\Tests\TestExtendBundle\Document\ArticleViewDocument
12 changes: 10 additions & 2 deletions Tests/Functional/Controller/ArticleControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,12 @@ public function testPutExtensions(
$this->assertNotEquals($article['title'], $response['title']);
$this->assertEquals($title, $response['title']);
$this->assertEquals($extensions['seo'], $response['ext']['seo']);
$this->assertEquals($extensions['excerpt'], $response['ext']['excerpt']);

// segment is only returned for sulu versions >= 2.2
$responseExcerpt = $response['ext']['excerpt'];
unset($response['segment']);

$this->assertEquals($extensions['excerpt'], $responseExcerpt);
}

public function testPutDifferentTemplate($title = 'Sulu', $description = 'Sulu is awesome')
Expand Down Expand Up @@ -1675,7 +1680,10 @@ private function findViewDocument($uuid, $locale)
/** @var Manager $manager */
$manager = $this->getContainer()->get('es.manager.default');

return $manager->find(ArticleViewDocument::class, $this->getViewDocumentId($uuid, $locale));
return $manager->find(
$this->getContainer()->getParameter('sulu_article.view_document.article.class'),
$this->getViewDocumentId($uuid, $locale)
);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions Tests/Functional/Controller/ArticlePageControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Sulu\Bundle\ArticleBundle\Tests\Functional\Controller;

use ONGR\ElasticsearchBundle\Service\Manager;
use Sulu\Bundle\ArticleBundle\Document\ArticleViewDocument;
use Sulu\Bundle\ArticleBundle\Document\ArticleViewDocumentInterface;
use Sulu\Bundle\ArticleBundle\Document\Index\IndexerInterface;
use Sulu\Bundle\ArticleBundle\Metadata\ArticleViewDocumentIdTrait;
Expand Down Expand Up @@ -408,7 +407,10 @@ private function findViewDocument($uuid, $locale)
/** @var Manager $manager */
$manager = $this->getContainer()->get('es.manager.default');

return $manager->find(ArticleViewDocument::class, $this->getViewDocumentId($uuid, $locale));
return $manager->find(
$this->getContainer()->getParameter('sulu_article.view_document.article.class'),
$this->getViewDocumentId($uuid, $locale)
);
}

private function getRoute($title, $page)
Expand Down
5 changes: 4 additions & 1 deletion Tests/Functional/Document/Index/ArticleIndexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,9 @@ private function createPage($title = 'Test Page', $resourceSegment = '/test-page
*/
private function findViewDocument($uuid, $locale = null)
{
return $this->manager->find(ArticleViewDocument::class, $uuid . '-' . ($locale ? $locale : $this->locale));
return $this->manager->find(
$this->getContainer()->getParameter('sulu_article.view_document.article.class'),
$uuid . '-' . ($locale ? $locale : $this->locale)
);
}
}
29 changes: 29 additions & 0 deletions Tests/TestExtendBundle/Document/ArticleViewDocument.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/*
* This file is part of Sulu.
*
* (c) Sulu 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\Tests\TestExtendBundle\Document;

use ONGR\ElasticsearchBundle\Annotation\Document;
use ONGR\ElasticsearchBundle\Annotation\Property;
use Sulu\Bundle\ArticleBundle\Document\ArticleViewDocument as SuluArticleViewDocument;

/**
* @Document(type="article")
*/
class ArticleViewDocument extends SuluArticleViewDocument
{
/**
* @var string
*
* @Property(type="text")
*/
public $article;
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"php": "^7.2",
"ext-json": "*",
"elasticsearch/elasticsearch": "^5.0 || ^6.0 || ^7.0",
"handcraftedinthealps/elasticsearch-bundle": "^5.2.6.2",
"handcraftedinthealps/elasticsearch-bundle": "^5.2.6.4",
"handcraftedinthealps/elasticsearch-dsl": "^5.0.7.1 || ^6.2.0.1 || ^7.2.0.1",
"jms/serializer": "^3.3",
"jms/serializer-bundle": "^3.3",
Expand Down

0 comments on commit 8db3708

Please sign in to comment.