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 all 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
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
14 changes: 12 additions & 2 deletions 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->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,
Expand All @@ -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,
]);
}

/**
Expand Down Expand Up @@ -175,6 +184,7 @@ private function resolveContentTranslateForm(
'content' => $content,
'contentUpdateStruct' => $contentUpdate,
'drafts_enabled' => true,
'intent' => 'translate',
]
);
}
Expand Down