From dcf6ff8d7f8e114aceeed07e0960eaaa5b72da0e Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Thu, 5 Dec 2024 14:08:30 +0100 Subject: [PATCH 1/3] IBX-9289: Move translations resolved in `NodeFactory` to node's extended info --- .../Content/ContentTreeController.php | 2 +- .../ValueObjectVisitor/ContentTree/Node.php | 2 -- .../ContentTree/NodeExtendedInfoVisitor.php | 17 ++++++++++++++ src/lib/REST/Value/ContentTree/Node.php | 17 +------------- .../Value/ContentTree/NodeExtendedInfo.php | 22 +++++++++++++++---- src/lib/UI/Module/ContentTree/NodeFactory.php | 8 ++++--- 6 files changed, 42 insertions(+), 26 deletions(-) diff --git a/src/bundle/Controller/Content/ContentTreeController.php b/src/bundle/Controller/Content/ContentTreeController.php index 372f914de5..92ad117f4f 100644 --- a/src/bundle/Controller/Content/ContentTreeController.php +++ b/src/bundle/Controller/Content/ContentTreeController.php @@ -194,7 +194,7 @@ public function loadNodeExtendedInfoAction(Location $location): NodeExtendedInfo fn (string $languageCode): bool => $this->isPreviewable($location, $content, $languageCode) ); - return new NodeExtendedInfo($locationPermissionRestrictions, $previewableTranslations); + return new NodeExtendedInfo($locationPermissionRestrictions, $previewableTranslations, $translations); } /** diff --git a/src/lib/REST/Output/ValueObjectVisitor/ContentTree/Node.php b/src/lib/REST/Output/ValueObjectVisitor/ContentTree/Node.php index f8d18f0bbb..fcee9b66da 100644 --- a/src/lib/REST/Output/ValueObjectVisitor/ContentTree/Node.php +++ b/src/lib/REST/Output/ValueObjectVisitor/ContentTree/Node.php @@ -39,8 +39,6 @@ public function visit(Visitor $visitor, Generator $generator, $data) $generator->valueElement('versionNo', $data->versionNo); - $generator->valueElement('translations', implode(',', $data->translations)); - $generator->valueElement('mainLanguageCode', $data->mainLanguageCode); $generator->startValueElement('name', $data->name); diff --git a/src/lib/REST/Output/ValueObjectVisitor/ContentTree/NodeExtendedInfoVisitor.php b/src/lib/REST/Output/ValueObjectVisitor/ContentTree/NodeExtendedInfoVisitor.php index 3d073f88d7..c080b4a631 100644 --- a/src/lib/REST/Output/ValueObjectVisitor/ContentTree/NodeExtendedInfoVisitor.php +++ b/src/lib/REST/Output/ValueObjectVisitor/ContentTree/NodeExtendedInfoVisitor.php @@ -31,6 +31,7 @@ public function visit(Visitor $visitor, Generator $generator, $data): void $this->buildPermissionNode($data->getPermissionRestrictions(), $generator); $this->buildPreviewableTranslationsNode($data->getPreviewableTranslations(), $generator); + $this->buildTranslationsNode($data->getTranslations(), $generator); $generator->endObjectElement(self::MAIN_ELEMENT); } @@ -51,6 +52,22 @@ protected function buildPreviewableTranslationsNode( $generator->endHashElement('previewableTranslations'); } + /** + * @param array $translations + */ + protected function buildTranslationsNode( + array $translations, + Generator $generator + ): void { + $generator->startHashElement('translations'); + $generator->startList('values'); + foreach ($translations as $value) { + $generator->valueElement('value', $value); + } + $generator->endList('values'); + $generator->endHashElement('translations'); + } + /** * @phpstan-param TPermissionRestrictions $permissionRestrictions */ diff --git a/src/lib/REST/Value/ContentTree/Node.php b/src/lib/REST/Value/ContentTree/Node.php index 9aa1755652..8e172614f9 100644 --- a/src/lib/REST/Value/ContentTree/Node.php +++ b/src/lib/REST/Value/ContentTree/Node.php @@ -23,9 +23,6 @@ class Node extends RestValue public int $versionNo; - /** @var string[] */ - public array $translations; - /** @var string */ public $name; @@ -56,24 +53,13 @@ class Node extends RestValue public string $mainLanguageCode; /** - * @param int $depth - * @param int $locationId - * @param int $contentId - * @param string[] $translations - * @param string $name - * @param string $contentTypeIdentifier - * @param bool $isContainer - * @param bool $isInvisible - * @param int $displayLimit - * @param int $totalChildrenCount - * @param \Ibexa\AdminUi\REST\Value\ContentTree\Node[] $children + * @param array<\Ibexa\AdminUi\REST\Value\ContentTree\Node> $children */ public function __construct( int $depth, int $locationId, int $contentId, int $versionNo, - array $translations, string $name, string $contentTypeIdentifier, bool $isContainer, @@ -90,7 +76,6 @@ public function __construct( $this->locationId = $locationId; $this->contentId = $contentId; $this->versionNo = $versionNo; - $this->translations = $translations; $this->name = $name; $this->isInvisible = $isInvisible; $this->contentTypeIdentifier = $contentTypeIdentifier; diff --git a/src/lib/REST/Value/ContentTree/NodeExtendedInfo.php b/src/lib/REST/Value/ContentTree/NodeExtendedInfo.php index 7258507c65..f1079b66a4 100644 --- a/src/lib/REST/Value/ContentTree/NodeExtendedInfo.php +++ b/src/lib/REST/Value/ContentTree/NodeExtendedInfo.php @@ -28,20 +28,26 @@ final class NodeExtendedInfo extends RestValue /** @phpstan-var TPermissionRestrictions|null */ private ?array $permissions; - /** @var string[] */ + /** @var array */ private array $previewableTranslations; + /** @var array */ + private array $translations; + /** * @phpstan-param TPermissionRestrictions|null $permissions * - * @param string[] $previewableTranslation + * @param array $previewableTranslation + * @param array $translations */ public function __construct( ?array $permissions = null, - array $previewableTranslation = [] + array $previewableTranslation = [], + array $translations = [] ) { $this->permissions = $permissions; $this->previewableTranslations = $previewableTranslation; + $this->translations = $translations; } /** @@ -53,10 +59,18 @@ public function getPermissionRestrictions(): ?array } /** - * @return string[] + * @return array */ public function getPreviewableTranslations(): array { return $this->previewableTranslations; } + + /** + * @return array + */ + public function getTranslations(): array + { + return $this->translations; + } } diff --git a/src/lib/UI/Module/ContentTree/NodeFactory.php b/src/lib/UI/Module/ContentTree/NodeFactory.php index 73c2a11fc9..ee283a097d 100644 --- a/src/lib/UI/Module/ContentTree/NodeFactory.php +++ b/src/lib/UI/Module/ContentTree/NodeFactory.php @@ -391,15 +391,17 @@ private function buildNode( } } - $translations = $versionInfo->getLanguageCodes(); - $mainLanguageCode = $versionInfo->getContentInfo()->getMainLanguageCode(); + //TODO tylko tego nie mamy + //$translations = $versionInfo->getLanguageCodes(); + + //TODO to mozemy z lokacji + $mainLanguageCode = $location->getContentInfo()->getMainLanguageCode(); return new Node( $depth, $location->getId(), $location->getContentId(), $versionInfo->getVersionNo(), - $translations, '', // node name will be provided later by `supplyTranslatedContentName` method null !== $contentType ? $contentType->getIdentifier() : '', null === $contentType || $contentType->isContainer(), From a0d63e1d8313588c31be8810955b20d674f0d6e0 Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Thu, 5 Dec 2024 14:58:40 +0100 Subject: [PATCH 2/3] IBX-9289: Remove dependency on Content --- src/lib/UI/Module/ContentTree/NodeFactory.php | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/lib/UI/Module/ContentTree/NodeFactory.php b/src/lib/UI/Module/ContentTree/NodeFactory.php index ee283a097d..1c00d55c29 100644 --- a/src/lib/UI/Module/ContentTree/NodeFactory.php +++ b/src/lib/UI/Module/ContentTree/NodeFactory.php @@ -356,9 +356,6 @@ private function buildNode( $containerLocations[] = $location; } - $content = $location->getContent(); - $versionInfo = $content->getVersionInfo(); - $limit = $this->resolveLoadLimit($loadSubtreeRequestNode); $offset = null !== $loadSubtreeRequestNode ? $loadSubtreeRequestNode->offset @@ -391,17 +388,11 @@ private function buildNode( } } - //TODO tylko tego nie mamy - //$translations = $versionInfo->getLanguageCodes(); - - //TODO to mozemy z lokacji - $mainLanguageCode = $location->getContentInfo()->getMainLanguageCode(); - return new Node( $depth, $location->getId(), $location->getContentId(), - $versionInfo->getVersionNo(), + $contentInfo->currentVersionNo, '', // node name will be provided later by `supplyTranslatedContentName` method null !== $contentType ? $contentType->getIdentifier() : '', null === $contentType || $contentType->isContainer(), @@ -410,7 +401,7 @@ private function buildNode( $totalChildrenCount, $this->getReverseRelationsCount($contentInfo), isset($bookmarkLocations[$location->getId()]), - $mainLanguageCode, + $contentInfo->getMainLanguageCode(), $children, $location->getPathString() ); From 01d0cfc9a102f2721be967b11e44b53917adff4c Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Thu, 5 Dec 2024 15:26:30 +0100 Subject: [PATCH 3/3] IBX-9289: Update integration tests --- .../REST/Schemas/ContentTreeNode.json | 2 -- .../Resources/REST/Schemas/ContentTreeNode.xsd | 2 -- .../Schemas/ContentTreeNodeExtendedInfo.json | 18 ++++++++++++++++-- .../Schemas/ContentTreeNodeExtendedInfo.xsd | 7 +++++++ ...ype-identifier-folder-and-landing-page.json | 5 ----- ...dentifier-folder-and-media-location-id.json | 2 -- ...tent-type-identifier-folder-or-subtree.json | 5 ----- ...lter-by-content-type-identifier-folder.json | 4 ---- .../ContentTreeNode/filter/json/no-filter.json | 6 ------ .../ContentTreeNode/filter/xml/no-filter.xml | 6 ------ .../Snapshots/ContentTreeNodeExtendedInfo.json | 3 +++ .../Snapshots/ContentTreeNodeExtendedInfo.xml | 3 +++ .../REST/Snapshots/ContentTreeRoot.json | 2 -- 13 files changed, 29 insertions(+), 36 deletions(-) diff --git a/tests/integration/Resources/REST/Schemas/ContentTreeNode.json b/tests/integration/Resources/REST/Schemas/ContentTreeNode.json index 8652632758..7c6c5c1537 100644 --- a/tests/integration/Resources/REST/Schemas/ContentTreeNode.json +++ b/tests/integration/Resources/REST/Schemas/ContentTreeNode.json @@ -88,7 +88,6 @@ "pathString", "contentId", "versionNo", - "translations", "name", "contentTypeIdentifier", "isContainer", @@ -109,7 +108,6 @@ "pathString", "contentId", "versionNo", - "translations", "name", "contentTypeIdentifier", "isContainer", diff --git a/tests/integration/Resources/REST/Schemas/ContentTreeNode.xsd b/tests/integration/Resources/REST/Schemas/ContentTreeNode.xsd index d3cd136b92..9da3d622eb 100644 --- a/tests/integration/Resources/REST/Schemas/ContentTreeNode.xsd +++ b/tests/integration/Resources/REST/Schemas/ContentTreeNode.xsd @@ -7,7 +7,6 @@ - @@ -24,7 +23,6 @@ - diff --git a/tests/integration/Resources/REST/Schemas/ContentTreeNodeExtendedInfo.json b/tests/integration/Resources/REST/Schemas/ContentTreeNodeExtendedInfo.json index 753b688a84..3d520aa1d9 100644 --- a/tests/integration/Resources/REST/Schemas/ContentTreeNodeExtendedInfo.json +++ b/tests/integration/Resources/REST/Schemas/ContentTreeNodeExtendedInfo.json @@ -66,12 +66,26 @@ ] } } - } + }, + "translations": { + "type": "object", + "properties": { + "values": { + "type": "array", + "items": [ + { + "type": "string" + } + ] + } + } + } }, "required": [ "_media-type", "permissions", - "previewableTranslations" + "previewableTranslations", + "translations" ] } }, diff --git a/tests/integration/Resources/REST/Schemas/ContentTreeNodeExtendedInfo.xsd b/tests/integration/Resources/REST/Schemas/ContentTreeNodeExtendedInfo.xsd index cd01c211ce..c9f6409121 100644 --- a/tests/integration/Resources/REST/Schemas/ContentTreeNodeExtendedInfo.xsd +++ b/tests/integration/Resources/REST/Schemas/ContentTreeNodeExtendedInfo.xsd @@ -33,6 +33,13 @@ + + + + + + + diff --git a/tests/integration/Resources/REST/Snapshots/ContentTreeNode/filter/json/filter-by-content-type-identifier-folder-and-landing-page.json b/tests/integration/Resources/REST/Snapshots/ContentTreeNode/filter/json/filter-by-content-type-identifier-folder-and-landing-page.json index b93aa863fd..2125da70f2 100644 --- a/tests/integration/Resources/REST/Snapshots/ContentTreeNode/filter/json/filter-by-content-type-identifier-folder-and-landing-page.json +++ b/tests/integration/Resources/REST/Snapshots/ContentTreeNode/filter/json/filter-by-content-type-identifier-folder-and-landing-page.json @@ -17,7 +17,6 @@ "pathString": "/1/2/", "reverseRelationsCount": 0, "totalChildrenCount": 0, - "translations": "eng-GB", "versionNo": 1 }, { @@ -35,7 +34,6 @@ "pathString": "/1/43/", "reverseRelationsCount": 0, "totalChildrenCount": 3, - "translations": "eng-US", "versionNo": 1 }, { @@ -53,7 +51,6 @@ "pathString": "/1/48/", "reverseRelationsCount": 0, "totalChildrenCount": 0, - "translations": "eng-US", "versionNo": 1 }, { @@ -71,7 +68,6 @@ "pathString": "/1/58/", "reverseRelationsCount": 0, "totalChildrenCount": 0, - "translations": "eng-US", "versionNo": 1 } ], @@ -87,7 +83,6 @@ "pathString": "/1/", "reverseRelationsCount": 0, "totalChildrenCount": 4, - "translations": "", "versionNo": 1 } } diff --git a/tests/integration/Resources/REST/Snapshots/ContentTreeNode/filter/json/filter-by-content-type-identifier-folder-and-media-location-id.json b/tests/integration/Resources/REST/Snapshots/ContentTreeNode/filter/json/filter-by-content-type-identifier-folder-and-media-location-id.json index 8d133ecb73..a5c583fdd9 100644 --- a/tests/integration/Resources/REST/Snapshots/ContentTreeNode/filter/json/filter-by-content-type-identifier-folder-and-media-location-id.json +++ b/tests/integration/Resources/REST/Snapshots/ContentTreeNode/filter/json/filter-by-content-type-identifier-folder-and-media-location-id.json @@ -17,7 +17,6 @@ "pathString": "/1/43/", "reverseRelationsCount": 0, "totalChildrenCount": 0, - "translations": "eng-US", "versionNo": 1 } ], @@ -33,7 +32,6 @@ "pathString": "/1/", "reverseRelationsCount": 0, "totalChildrenCount": 1, - "translations": "", "versionNo": 1 } } diff --git a/tests/integration/Resources/REST/Snapshots/ContentTreeNode/filter/json/filter-by-content-type-identifier-folder-or-subtree.json b/tests/integration/Resources/REST/Snapshots/ContentTreeNode/filter/json/filter-by-content-type-identifier-folder-or-subtree.json index 240568a68f..c93a0a1d7c 100644 --- a/tests/integration/Resources/REST/Snapshots/ContentTreeNode/filter/json/filter-by-content-type-identifier-folder-or-subtree.json +++ b/tests/integration/Resources/REST/Snapshots/ContentTreeNode/filter/json/filter-by-content-type-identifier-folder-or-subtree.json @@ -17,7 +17,6 @@ "pathString": "/1/43/", "reverseRelationsCount": 0, "totalChildrenCount": 3, - "translations": "eng-US", "versionNo": 1 }, { @@ -35,7 +34,6 @@ "pathString": "/1/48/", "reverseRelationsCount": 0, "totalChildrenCount": 0, - "translations": "eng-US", "versionNo": 1 }, { @@ -53,7 +51,6 @@ "pathString": "/1/5/", "reverseRelationsCount": 0, "totalChildrenCount": 5, - "translations": "eng-US", "versionNo": 1 }, { @@ -71,7 +68,6 @@ "pathString": "/1/58/", "reverseRelationsCount": 0, "totalChildrenCount": 0, - "translations": "eng-US", "versionNo": 1 } ], @@ -87,7 +83,6 @@ "pathString": "/1/", "reverseRelationsCount": 0, "totalChildrenCount": 4, - "translations": "", "versionNo": 1 } } diff --git a/tests/integration/Resources/REST/Snapshots/ContentTreeNode/filter/json/filter-by-content-type-identifier-folder.json b/tests/integration/Resources/REST/Snapshots/ContentTreeNode/filter/json/filter-by-content-type-identifier-folder.json index ded51eb7fd..362e61fad0 100644 --- a/tests/integration/Resources/REST/Snapshots/ContentTreeNode/filter/json/filter-by-content-type-identifier-folder.json +++ b/tests/integration/Resources/REST/Snapshots/ContentTreeNode/filter/json/filter-by-content-type-identifier-folder.json @@ -17,7 +17,6 @@ "pathString": "/1/43/", "reverseRelationsCount": 0, "totalChildrenCount": 3, - "translations": "eng-US", "versionNo": 1 }, { @@ -35,7 +34,6 @@ "pathString": "/1/48/", "reverseRelationsCount": 0, "totalChildrenCount": 0, - "translations": "eng-US", "versionNo": 1 }, { @@ -53,7 +51,6 @@ "pathString": "/1/58/", "reverseRelationsCount": 0, "totalChildrenCount": 0, - "translations": "eng-US", "versionNo": 1 } ], @@ -69,7 +66,6 @@ "pathString": "/1/", "reverseRelationsCount": 0, "totalChildrenCount": 3, - "translations": "", "versionNo": 1 } } diff --git a/tests/integration/Resources/REST/Snapshots/ContentTreeNode/filter/json/no-filter.json b/tests/integration/Resources/REST/Snapshots/ContentTreeNode/filter/json/no-filter.json index 0337e22d7e..0892041a5a 100644 --- a/tests/integration/Resources/REST/Snapshots/ContentTreeNode/filter/json/no-filter.json +++ b/tests/integration/Resources/REST/Snapshots/ContentTreeNode/filter/json/no-filter.json @@ -17,7 +17,6 @@ "pathString": "/1/2/", "reverseRelationsCount": 0, "totalChildrenCount": 1, - "translations": "eng-GB", "versionNo": 1 }, { @@ -35,7 +34,6 @@ "pathString": "/1/43/", "reverseRelationsCount": 0, "totalChildrenCount": 3, - "translations": "eng-US", "versionNo": 1 }, { @@ -53,7 +51,6 @@ "pathString": "/1/48/", "reverseRelationsCount": 0, "totalChildrenCount": 0, - "translations": "eng-US", "versionNo": 1 }, { @@ -71,7 +68,6 @@ "pathString": "/1/5/", "reverseRelationsCount": 0, "totalChildrenCount": 5, - "translations": "eng-US", "versionNo": 1 }, { @@ -89,7 +85,6 @@ "pathString": "/1/58/", "reverseRelationsCount": 0, "totalChildrenCount": 0, - "translations": "eng-US", "versionNo": 1 } ], @@ -105,7 +100,6 @@ "pathString": "/1/", "reverseRelationsCount": 0, "totalChildrenCount": 5, - "translations": "", "versionNo": 1 } } diff --git a/tests/integration/Resources/REST/Snapshots/ContentTreeNode/filter/xml/no-filter.xml b/tests/integration/Resources/REST/Snapshots/ContentTreeNode/filter/xml/no-filter.xml index e4a55a1fc0..a28ef0d08a 100644 --- a/tests/integration/Resources/REST/Snapshots/ContentTreeNode/filter/xml/no-filter.xml +++ b/tests/integration/Resources/REST/Snapshots/ContentTreeNode/filter/xml/no-filter.xml @@ -4,7 +4,6 @@ /1/ 0 1 - eng-GB @@ -19,7 +18,6 @@ /1/2/ 57 1 - eng-GB eng-GB Home landing_page @@ -35,7 +33,6 @@ /1/43/ 41 1 - eng-US eng-US Media folder @@ -51,7 +48,6 @@ /1/48/ 45 1 - eng-US eng-US Setup folder @@ -67,7 +63,6 @@ /1/5/ 4 1 - eng-US eng-US Users user_group @@ -83,7 +78,6 @@ /1/58/ 56 1 - eng-US eng-US Design folder diff --git a/tests/integration/Resources/REST/Snapshots/ContentTreeNodeExtendedInfo.json b/tests/integration/Resources/REST/Snapshots/ContentTreeNodeExtendedInfo.json index 85be359381..25a913466a 100644 --- a/tests/integration/Resources/REST/Snapshots/ContentTreeNodeExtendedInfo.json +++ b/tests/integration/Resources/REST/Snapshots/ContentTreeNodeExtendedInfo.json @@ -38,6 +38,9 @@ ], "previewableTranslations": { "values": ["eng-GB"] + }, + "translations": { + "values": ["eng-GB"] } } } diff --git a/tests/integration/Resources/REST/Snapshots/ContentTreeNodeExtendedInfo.xml b/tests/integration/Resources/REST/Snapshots/ContentTreeNodeExtendedInfo.xml index 926eeef47f..2fd90b0e52 100644 --- a/tests/integration/Resources/REST/Snapshots/ContentTreeNodeExtendedInfo.xml +++ b/tests/integration/Resources/REST/Snapshots/ContentTreeNodeExtendedInfo.xml @@ -26,4 +26,7 @@ eng-GB + + eng-GB + diff --git a/tests/integration/Resources/REST/Snapshots/ContentTreeRoot.json b/tests/integration/Resources/REST/Snapshots/ContentTreeRoot.json index 1a7c7c051d..aacf1ed1bd 100644 --- a/tests/integration/Resources/REST/Snapshots/ContentTreeRoot.json +++ b/tests/integration/Resources/REST/Snapshots/ContentTreeRoot.json @@ -8,7 +8,6 @@ "mainLanguageCode": "eng-GB", "contentId": 57, "versionNo": 1, - "translations": "eng-GB", "name": "Home", "pathString": "/1/2/", "contentTypeIdentifier": "landing_page", @@ -25,7 +24,6 @@ "mainLanguageCode": "eng-GB", "contentId": 58, "versionNo": 1, - "translations": "eng-GB", "name": "Contact Us", "pathString": "/1/2/60/", "contentTypeIdentifier": "feedback_form",