Skip to content
New issue

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

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

Already on GitHub? # to your account

IBX-5640: Added available translations to dashboard data #2099

Merged
merged 3 commits into from
May 12, 2023
Merged
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
35 changes: 27 additions & 8 deletions src/lib/Tab/Dashboard/PagerLocationToDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
namespace Ibexa\AdminUi\Tab\Dashboard;

use eZ\Publish\API\Repository\ContentService;
use eZ\Publish\API\Repository\ContentTypeService;
use eZ\Publish\API\Repository\Exceptions\NotFoundException;
use eZ\Publish\API\Repository\LanguageService;
use eZ\Publish\API\Repository\UserService;
use eZ\Publish\API\Repository\Values\Content\Language;
use eZ\Publish\API\Repository\Values\Content\VersionInfo;
use eZ\Publish\API\Repository\Values\User\User;
use eZ\Publish\Core\Repository\LocationResolver\LocationResolver;
Expand All @@ -22,25 +23,25 @@ final class PagerLocationToDataMapper
/** @var \eZ\Publish\API\Repository\ContentService */
private $contentService;

/** @var \eZ\Publish\API\Repository\ContentTypeService */
private $contentTypeService;

/** @var \eZ\Publish\API\Repository\UserService */
private $userService;

/** @var \eZ\Publish\Core\Repository\LocationResolver\LocationResolver */
private $locationResolver;

/** @var \eZ\Publish\API\Repository\LanguageService */
private $languageService;

public function __construct(
ContentService $contentService,
ContentTypeService $contentTypeService,
UserService $userService,
LocationResolver $locationResolver
LocationResolver $locationResolver,
LanguageService $languageService
) {
$this->contentService = $contentService;
$this->contentTypeService = $contentTypeService;
$this->userService = $userService;
$this->locationResolver = $locationResolver;
$this->languageService = $languageService;
}

/**
Expand All @@ -65,7 +66,7 @@ public function map(Pagerfanta $pager, bool $doMapVersionInfoData = false): arra
'name' => $contentInfo->name,
'type' => $contentType->getName(),
'language' => $contentInfo->mainLanguageCode,
'available_enabled_translations' => [],
'available_enabled_translations' => $versionInfo !== null ? $this->getAvailableTranslations($versionInfo) : [],
'contributor' => $versionInfo !== null ? $this->getVersionContributor($versionInfo) : null,
'content_type' => $contentType,
'modified' => $contentInfo->modificationDate,
Expand All @@ -84,4 +85,22 @@ private function getVersionContributor(VersionInfo $versionInfo): ?User
return null;
}
}

/**
* @return \eZ\Publish\API\Repository\Values\Content\Language[]
*/
private function getAvailableTranslations(
VersionInfo $versionInfo
): array {
$availableTranslationsLanguages = $this->languageService->loadLanguageListByCode(
$versionInfo->languageCodes
);

return array_filter(
$availableTranslationsLanguages,
static function (Language $language): bool {
return $language->enabled;
}
);
}
}