Skip to content

Commit

Permalink
IBX-9289: Move translations resolved in NodeFactory to node's exten…
Browse files Browse the repository at this point in the history
…ded info
  • Loading branch information
barw4 committed Dec 5, 2024
1 parent 05b9c71 commit 3a9c5c6
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/bundle/Controller/Content/ContentTreeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/lib/REST/Output/ValueObjectVisitor/ContentTree/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -51,6 +52,22 @@ protected function buildPreviewableTranslationsNode(
$generator->endHashElement('previewableTranslations');
}

/**
* @param array<int, string> $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
*/
Expand Down
17 changes: 1 addition & 16 deletions src/lib/REST/Value/ContentTree/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ class Node extends RestValue

public int $versionNo;

/** @var string[] */
public array $translations;

/** @var string */
public $name;

Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down
22 changes: 18 additions & 4 deletions src/lib/REST/Value/ContentTree/NodeExtendedInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,26 @@ final class NodeExtendedInfo extends RestValue
/** @phpstan-var TPermissionRestrictions|null */
private ?array $permissions;

/** @var string[] */
/** @var array<int, string> */
private array $previewableTranslations;

/** @var array<int, string> */
private array $translations;

/**
* @phpstan-param TPermissionRestrictions|null $permissions
*
* @param string[] $previewableTranslation
* @param array<int, string> $previewableTranslation
* @param array<int, string> $translations
*/
public function __construct(
?array $permissions = null,
array $previewableTranslation = []
array $previewableTranslation = [],
array $translations = []
) {
$this->permissions = $permissions;
$this->previewableTranslations = $previewableTranslation;
$this->translations = $translations;
}

/**
Expand All @@ -53,10 +59,18 @@ public function getPermissionRestrictions(): ?array
}

/**
* @return string[]
* @return array<int, string>
*/
public function getPreviewableTranslations(): array
{
return $this->previewableTranslations;
}

/**
* @return array<int, string>
*/
public function getTranslations(): array
{
return $this->translations;
}
}
8 changes: 5 additions & 3 deletions src/lib/UI/Module/ContentTree/NodeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 3a9c5c6

Please sign in to comment.