diff --git a/src/bundle/Controller/ContentEditController.php b/src/bundle/Controller/ContentEditController.php index cd573975b6..e75d3de5a0 100644 --- a/src/bundle/Controller/ContentEditController.php +++ b/src/bundle/Controller/ContentEditController.php @@ -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, diff --git a/src/lib/EventListener/ContentProxyCreateDraftListener.php b/src/lib/EventListener/ContentProxyCreateDraftListener.php index 2bafb4023c..1d26a3fb03 100644 --- a/src/lib/EventListener/ContentProxyCreateDraftListener.php +++ b/src/lib/EventListener/ContentProxyCreateDraftListener.php @@ -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, ]) ); diff --git a/src/lib/Form/Data/ContentTranslationData.php b/src/lib/Form/Data/ContentTranslationData.php index 570fd78107..e1debe26d1 100644 --- a/src/lib/Form/Data/ContentTranslationData.php +++ b/src/lib/Form/Data/ContentTranslationData.php @@ -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[] @@ -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; diff --git a/src/lib/Form/Data/FormMapper/ContentTranslationMapper.php b/src/lib/Form/Data/FormMapper/ContentTranslationMapper.php index 238d8edc64..3fbbb549f1 100644 --- a/src/lib/Form/Data/FormMapper/ContentTranslationMapper.php +++ b/src/lib/Form/Data/FormMapper/ContentTranslationMapper.php @@ -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) { diff --git a/src/lib/Form/Processor/TranslationFormProcessor.php b/src/lib/Form/Processor/TranslationFormProcessor.php index 5ba4552580..6ba58fb0e7 100644 --- a/src/lib/Form/Processor/TranslationFormProcessor.php +++ b/src/lib/Form/Processor/TranslationFormProcessor.php @@ -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; @@ -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) { + $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; diff --git a/src/lib/Tests/EventListener/ContentProxyCreateDraftListenerTest.php b/src/lib/Tests/EventListener/ContentProxyCreateDraftListenerTest.php index 0cd7608d55..1ad08d047d 100644 --- a/src/lib/Tests/EventListener/ContentProxyCreateDraftListenerTest.php +++ b/src/lib/Tests/EventListener/ContentProxyCreateDraftListenerTest.php @@ -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'); diff --git a/src/lib/Tests/Form/Data/FormMapper/ContentTranslationMapperTest.php b/src/lib/Tests/Form/Data/FormMapper/ContentTranslationMapperTest.php index 5678f106f9..e7a5526d7a 100644 --- a/src/lib/Tests/Form/Data/FormMapper/ContentTranslationMapperTest.php +++ b/src/lib/Tests/Form/Data/FormMapper/ContentTranslationMapperTest.php @@ -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([ @@ -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([ @@ -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([ diff --git a/src/lib/View/Filter/ContentTranslateViewFilter.php b/src/lib/View/Filter/ContentTranslateViewFilter.php index 343db22764..0286c7a36d 100644 --- a/src/lib/View/Filter/ContentTranslateViewFilter.php +++ b/src/lib/View/Filter/ContentTranslateViewFilter.php @@ -95,9 +95,11 @@ public function handleContentTranslateForm(FilterViewBuilderParametersEvent $eve $request = $event->getRequest(); $languageCode = $request->attributes->get('toLanguageCode'); $baseLanguageCode = $request->attributes->get('fromLanguageCode'); + $versionNo = $request->query->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, @@ -118,7 +120,14 @@ public function handleContentTranslateForm(FilterViewBuilderParametersEvent $eve $content ); - $event->getParameters()->add(['form' => $form->handleRequest($request)]); + $event->getParameters()->add([ + 'form' => $form->handleRequest($request), + 'content' => $content, + 'versionNo' => $versionNo, + 'contentType' => $contentType, + 'toLanguage' => $toLanguage, + 'fromLanguage' => $fromLanguage, + ]); } /** @@ -175,6 +184,7 @@ private function resolveContentTranslateForm( 'content' => $content, 'contentUpdateStruct' => $contentUpdate, 'drafts_enabled' => true, + 'intent' => 'translate', ] ); }