Skip to content

Commit

Permalink
Fix for the add new locale dialog (#654)
Browse files Browse the repository at this point in the history
* Fix copy locale dialog

* Add deprecation

* Fix tests
  • Loading branch information
Prokyonn authored Jan 10, 2024
1 parent 3d44c86 commit 42a7600
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 39 deletions.
31 changes: 30 additions & 1 deletion Controller/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
use Sulu\Bundle\ArticleBundle\Document\Index\DocumentFactoryInterface;
use Sulu\Bundle\ArticleBundle\ListBuilder\ElasticSearchFieldDescriptor;
use Sulu\Bundle\ArticleBundle\Metadata\ArticleViewDocumentIdTrait;
use Sulu\Bundle\DocumentManagerBundle\Bridge\DocumentInspector;
use Sulu\Component\Content\Document\LocalizationState;
use Sulu\Component\Content\Form\Exception\InvalidFormException;
use Sulu\Component\Content\Mapper\ContentMapperInterface;
use Sulu\Component\DocumentManager\DocumentManagerInterface;
Expand Down Expand Up @@ -111,6 +113,11 @@ class ArticleController extends AbstractRestController implements ClassResourceI
*/
private $displayTabAll;

/**
* @var DocumentInspector|null
*/
private $documentInspector;

public function __construct(
ViewHandlerInterface $viewHandler,
DocumentManagerInterface $documentManager,
Expand All @@ -123,7 +130,8 @@ public function __construct(
RequestHashCheckerInterface $requestHashChecker,
SecurityCheckerInterface $securityChecker,
bool $displayTabAll,
?TokenStorageInterface $tokenStorage = null
?TokenStorageInterface $tokenStorage = null,
?DocumentInspector $documentInspector = null
) {
parent::__construct($viewHandler, $tokenStorage);

Expand All @@ -137,6 +145,11 @@ public function __construct(
$this->requestHashChecker = $requestHashChecker;
$this->securityChecker = $securityChecker;
$this->displayTabAll = $displayTabAll;
$this->documentInspector = $documentInspector;

if (null === $this->documentInspector) {
@trigger_deprecation('sulu/article-bundle', '2.5', 'Instantiating the ArticleController without the $documentInspector argument is deprecated!');
}
}

/**
Expand Down Expand Up @@ -413,11 +426,27 @@ private function getRangeQuery(string $field, string $from, string $to): RangeQu
public function getAction(Request $request, string $id): Response
{
$locale = $this->getRequestParameter($request, 'locale', true);
/** @var ArticleDocument $document */
$document = $this->documentManager->find(
$id,
$locale
);

if ($this->documentInspector) {
$localizationState = $this->documentInspector->getLocalizationState($document);

if (LocalizationState::GHOST === $localizationState) {
$document = $this->documentManager->find(
$id,
$locale,
[
'load_ghost_content' => false,
'structure_type' => $document->getStructureType(),
]
);
}
}

$context = new Context();
$context->setSerializeNull(true);
$context->setGroups(['defaultPage', 'defaultArticle', 'smallArticlePage']);
Expand Down
1 change: 1 addition & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<argument type="service" id="sulu_security.security_checker"/>
<argument>%sulu_article.display_tab_all%</argument>
<argument type="service" id="security.token_storage"/>
<argument type="service" id="sulu_document_manager.document_inspector"/>

<tag name="sulu.context" context="admin"/>
</service>
Expand Down
6 changes: 0 additions & 6 deletions Resources/doc/default.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,4 @@
<div>
{{ content.article|default()|raw }}
</div>

<ul>
{% for page in pages %}
<li><a href="{{ sulu_content_path(page.routePath) }}">{{ page.title|default('Page '~page.pageNumber) }}</a></li>
{% endfor %}
</ul>
{% endblock %}
2 changes: 1 addition & 1 deletion Tests/Application/.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
APP_ENV=test
DATABASE_URL=mysql://root:ChangeMe@127.0.0.1:3306/sulu_test?serverVersion=5.7
DATABASE_URL=mysql://root:@127.0.0.1:3306/sulu_test?serverVersion=5.7
DATABASE_CHARSET=utf8mb4
DATABASE_COLLATE=utf8mb4_unicode_ci
ELASTICSEARCH_HOST=127.0.0.1:9200
12 changes: 5 additions & 7 deletions Tests/Functional/Controller/ArticleControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@ public function testPutCustomWebspaceSettings($title, $locale, $mainWebspace = n

// test that ghost do not serve default webspace settings
$response = $this->get($article['id'], 'en');
$this->assertEquals($title, $response['title']);
$this->assertEquals('sulu_io', $response['mainWebspace']);
$this->assertEquals([], $response['additionalWebspaces']);

Expand Down Expand Up @@ -415,7 +414,7 @@ public function testPutCustomWebspaceSettingsWithShadow($title, $locale, $mainWe
$this->assertEquals($additionalWebspaces ?? [], $viewDocument->getAdditionalWebspaces());
}

public function testGetGhost()
public function testGetEmptyDocument()
{
$title = 'Sulu ist toll';
$article = $this->testPut($title, 'de');
Expand All @@ -425,11 +424,10 @@ public function testGetGhost()
$this->assertHttpStatusCode(200, $this->client->getResponse());

$response = \json_decode($this->client->getResponse()->getContent(), true);
$this->assertNotEquals($article['title'], $response['title']);
$this->assertEquals($title, $response['title']);
$this->assertEquals('2016-01-01', \date('Y-m-d', \strtotime($response['authored'])));
$this->assertEquals($this->getTestUser()->getContact()->getId(), $response['author']);
$this->assertEquals(['name' => 'ghost', 'value' => 'de'], $response['type']);
$this->assertEquals('', $response['title']);
$this->assertEquals(null, $response['authored']);
$this->assertEquals(null, $response['author']);
$this->assertEquals($article['template'], $response['template']);
}

public function testGetShadow()
Expand Down
24 changes: 0 additions & 24 deletions Tests/Functional/Controller/ArticlePageControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,30 +284,6 @@ public function testDelete()
$this->assertCount(0, $articleViewDocument->getPages());
}

public function testHandleGhostArticlePageAndArticle($pageTitle = 'Sulu is awesome')
{
$article = $this->createArticle();
$page = $this->post($article);

$this->client->jsonRequest(
'PUT',
'/api/articles/' . $article['id'] . '/pages/' . $page['id'] . '?locale=en',
[
'pageTitle' => $pageTitle,
]
);

$response = \json_decode($this->client->getResponse()->getContent(), true);
$this->assertHttpStatusCode(200, $this->client->getResponse());

$this->assertArrayNotHasKey('type', $response);
$this->assertEquals($pageTitle, $response['pageTitle']);

// article should stay ghost
$article = $this->getArticle($article['id'], 'en');
$this->assertEquals('ghost', $article['type']['name']);
}

public function testHandleSecondLocale($title = 'Sulu ist toll')
{
$articleDE = $this->createArticle($title);
Expand Down

0 comments on commit 42a7600

Please sign in to comment.