Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-3265: Fixed translation of User Content Objects #2081

Open
wants to merge 5 commits into
base: 2.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bundle/Controller/ContentEditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function proxyTranslateAction(
return $event->getResponse();
}

// Fallback to "translate"
// Fallback to default translation interface (no draft)
return $this->redirectToRoute('ezplatform.content.translate', [
'contentId' => $contentId,
'fromLanguageCode' => $fromLanguageCode,
Expand Down
3 changes: 2 additions & 1 deletion src/bundle/Resources/config/routing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -564,11 +564,12 @@ ibexa.content.translate_with_location.proxy:
fromLanguageCode: ~

ezplatform.content.translate:
path: /content/{contentId}/translate/{toLanguageCode}/{fromLanguageCode}
path: /content/{contentId}/translate/{toLanguageCode}/{fromLanguageCode}/{versionNo}
methods: ['GET', 'POST']
defaults:
_controller: 'EzSystems\EzPlatformAdminUiBundle\Controller\ContentEditController::translateAction'
fromLanguageCode: ~
versionNo: ~

ibexa.content.translate_with_location:
path: /content/{contentId}/location/{locationId}/translate/{toLanguageCode}/{fromLanguageCode}
Expand Down
5 changes: 3 additions & 2 deletions src/lib/EventListener/ContentProxyCreateDraftListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,12 @@ public function translate(ContentProxyTranslateEvent $event): void
);

$response = new RedirectResponse(
$this->router->generate('ezplatform.content.draft.edit', [
$this->router->generate('ezplatform.content.translate', [
'contentId' => $contentDraft->id,
'versionNo' => $contentDraft->getVersionInfo()->versionNo,
'language' => $toLanguageCode,
'locationId' => $event->getLocationId(),
'fromLanguageCode' => $fromLanguageCode,
'toLanguageCode' => $toLanguageCode,
])
);

Expand Down
7 changes: 5 additions & 2 deletions src/lib/Form/Data/ContentTranslationData.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

namespace EzSystems\EzPlatformAdminUi\Form\Data;

use eZ\Publish\Core\Repository\Values\Content\ContentUpdateStruct;
use EzSystems\EzPlatformContentForms\Data\Content\FieldData;
use EzSystems\EzPlatformContentForms\Data\ContentTranslationData as BaseContentTranslationData;
use Symfony\Component\Validator\Constraints as Assert;

class ContentTranslationData extends ContentUpdateStruct implements NewnessCheckable
class ContentTranslationData extends BaseContentTranslationData implements NewnessCheckable
{
/**
* @var \EzSystems\EzPlatformContentForms\Data\Content\FieldData[]
Expand All @@ -23,6 +23,9 @@ class ContentTranslationData extends ContentUpdateStruct implements NewnessCheck
/** @var \eZ\Publish\API\Repository\Values\Content\Content */
protected $content;

/** @var \eZ\Publish\API\Repository\Values\Content\VersionInfo */
protected $versionInfo;

/** @var \eZ\Publish\API\Repository\Values\ContentType\ContentType */
protected $contentType;

Expand Down
6 changes: 5 additions & 1 deletion src/lib/Form/Data/FormMapper/ContentTranslationMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ public function mapToFormData(ValueObject $content, array $params = [])
/** @var \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType */
$contentType = $params['contentType'];

$data = new ContentTranslationData(['content' => $content, 'contentType' => $contentType]);
$data = new ContentTranslationData([
'content' => $content,
'versionInfo' => $content->getVersionInfo(),
'contentType' => $contentType,
]);
$data->initialLanguageCode = $language->languageCode;

foreach ($content->getFieldsByLanguage() as $field) {
Expand Down
8 changes: 7 additions & 1 deletion src/lib/Form/Processor/TranslationFormProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace EzSystems\EzPlatformAdminUi\Form\Processor;

use eZ\Publish\API\Repository\ContentService;
use eZ\Publish\API\Repository\Values\Content\VersionInfo;
use EzSystems\EzPlatformAdminUi\Form\Data\ContentTranslationData;
use EzSystems\EzPlatformContentForms\Data\Content\ContentUpdateData;
use EzSystems\EzPlatformContentForms\Data\Content\FieldData;
Expand Down Expand Up @@ -54,7 +55,12 @@ public function createContentDraft(FormActionEvent $event): void
return;
}

$contentDraft = $this->contentService->createContentDraft($data->content->contentInfo);
if ($data->content->getVersionInfo()->status === VersionInfo::STATUS_DRAFT) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$data->content can be a variable since it's used in all cases.

$contentDraft = $data->content;
} else {
$contentDraft = $this->contentService->createContentDraft($data->content->contentInfo);
}

$fields = array_filter($data->fieldsData, static function (FieldData $fieldData) use ($contentDraft, $data) {
$mainLanguageCode = $contentDraft->getVersionInfo()->getContentInfo()->mainLanguageCode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,11 @@ public function testTranslateContentAutosaveEnabled(): void
$router = $this->createMock(RouterInterface::class);
$router
->method('generate')
->with('ezplatform.content.draft.edit', [
->with('ezplatform.content.translate', [
'contentId' => null,
'versionNo' => null,
'language' => 'pol-PL',
'toLanguageCode' => 'pol-PL',
'fromLanguageCode' => 'eng-GB',
'locationId' => null,
])
->willReturn('redirect_test_url');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function paramsProvider(): array
],
new ContentTranslationData([
'content' => $content_with_1_field,
'versionInfo' => $content_with_1_field->getVersionInfo(),
'initialLanguageCode' => self::LANGUAGE_CODE,
'fieldsData' => [
$field1->fieldDefIdentifier => new FieldData([
Expand All @@ -100,6 +101,7 @@ public function paramsProvider(): array
],
new ContentTranslationData([
'content' => $content_with_1_field,
'versionInfo' => $content_with_1_field->getVersionInfo(),
'initialLanguageCode' => self::LANGUAGE_CODE,
'fieldsData' => [
$field1->fieldDefIdentifier => new FieldData([
Expand All @@ -120,6 +122,7 @@ public function paramsProvider(): array
],
new ContentTranslationData([
'content' => $content_with_3_fields,
'versionInfo' => $content_with_3_fields->getVersionInfo(),
'initialLanguageCode' => self::LANGUAGE_CODE,
'fieldsData' => [
$field1->fieldDefIdentifier => new FieldData([
Expand Down
3 changes: 2 additions & 1 deletion src/lib/View/Builder/ContentTranslateViewBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ private function resolveContent(array $parameters, ?Location $location, ?Languag

return $this->loadContent(
(int) $parameters['contentId'],
null !== $language ? [$language->languageCode] : []
null !== $language ? [$language->languageCode] : [],
(int) $parameters['versionNo'] ?: null
);
}

Expand Down
5 changes: 4 additions & 1 deletion src/lib/View/Filter/ContentTranslateViewFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ public function handleContentTranslateForm(FilterViewBuilderParametersEvent $eve
$request = $event->getRequest();
$languageCode = $request->attributes->get('toLanguageCode');
$baseLanguageCode = $request->attributes->get('fromLanguageCode');
$versionNo = $request->attributes->getInt('versionNo');
$content = $this->contentService->loadContent(
(int)$request->attributes->get('contentId'),
null !== $baseLanguageCode ? [$baseLanguageCode] : null
null !== $baseLanguageCode ? [$baseLanguageCode] : null,
$versionNo ?: null
);
$contentType = $this->contentTypeService->loadContentType(
$content->getContentType()->id,
Expand Down Expand Up @@ -175,6 +177,7 @@ private function resolveContentTranslateForm(
'content' => $content,
'contentUpdateStruct' => $contentUpdate,
'drafts_enabled' => true,
'intent' => 'translate',
]
);
}
Expand Down