From 2acf053bd270b4c25cef0f7f473606eec9e9c7f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Parafi=C5=84ski?= Date: Fri, 28 Apr 2023 12:41:23 +0200 Subject: [PATCH 1/3] IBX-5640: Added available translations to dashboard data --- .../Dashboard/PagerLocationToDataMapper.php | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/lib/Tab/Dashboard/PagerLocationToDataMapper.php b/src/lib/Tab/Dashboard/PagerLocationToDataMapper.php index 2ebdc23f43..8f76e158ac 100644 --- a/src/lib/Tab/Dashboard/PagerLocationToDataMapper.php +++ b/src/lib/Tab/Dashboard/PagerLocationToDataMapper.php @@ -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; @@ -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; } /** @@ -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, @@ -84,4 +85,22 @@ private function getVersionContributor(VersionInfo $versionInfo): ?User return null; } } + + /** + * @return iterable<\eZ\Publish\API\Repository\Values\Content\Language> + */ + protected function getAvailableTranslations( + VersionInfo $versionInfo + ): iterable { + $availableTranslationsLanguages = $this->languageService->loadLanguageListByCode( + $versionInfo->languageCodes + ); + + return array_filter( + $availableTranslationsLanguages, + (static function (Language $language): bool { + return $language->enabled; + }) + ); + } } From 83a9351cd19cc122eb2321215ec301dc9c7a1fcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Parafi=C5=84ski?= Date: Fri, 28 Apr 2023 12:49:27 +0200 Subject: [PATCH 2/3] Changed visibility to private --- src/lib/Tab/Dashboard/PagerLocationToDataMapper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/Tab/Dashboard/PagerLocationToDataMapper.php b/src/lib/Tab/Dashboard/PagerLocationToDataMapper.php index 8f76e158ac..cb86f68bbc 100644 --- a/src/lib/Tab/Dashboard/PagerLocationToDataMapper.php +++ b/src/lib/Tab/Dashboard/PagerLocationToDataMapper.php @@ -89,7 +89,7 @@ private function getVersionContributor(VersionInfo $versionInfo): ?User /** * @return iterable<\eZ\Publish\API\Repository\Values\Content\Language> */ - protected function getAvailableTranslations( + private function getAvailableTranslations( VersionInfo $versionInfo ): iterable { $availableTranslationsLanguages = $this->languageService->loadLanguageListByCode( From 6ef785916cdad267d2c8cfe38114a90c64f26cf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Parafi=C5=84ski?= Date: Fri, 28 Apr 2023 13:10:17 +0200 Subject: [PATCH 3/3] CR fixes --- src/lib/Tab/Dashboard/PagerLocationToDataMapper.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/Tab/Dashboard/PagerLocationToDataMapper.php b/src/lib/Tab/Dashboard/PagerLocationToDataMapper.php index cb86f68bbc..13cc36d7e5 100644 --- a/src/lib/Tab/Dashboard/PagerLocationToDataMapper.php +++ b/src/lib/Tab/Dashboard/PagerLocationToDataMapper.php @@ -87,20 +87,20 @@ private function getVersionContributor(VersionInfo $versionInfo): ?User } /** - * @return iterable<\eZ\Publish\API\Repository\Values\Content\Language> + * @return \eZ\Publish\API\Repository\Values\Content\Language[] */ private function getAvailableTranslations( VersionInfo $versionInfo - ): iterable { + ): array { $availableTranslationsLanguages = $this->languageService->loadLanguageListByCode( $versionInfo->languageCodes ); return array_filter( $availableTranslationsLanguages, - (static function (Language $language): bool { + static function (Language $language): bool { return $language->enabled; - }) + } ); } }