-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EZP-30344: Implemented Translation Limitation
- Loading branch information
1 parent
4f40acd
commit c537959
Showing
12 changed files
with
292 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
src/lib/Form/Type/ChoiceList/Loader/ContentEditTranslationChoiceLoader.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\EzPlatformAdminUi\Form\Type\ChoiceList\Loader; | ||
|
||
use eZ\Publish\API\Repository\LanguageService; | ||
use eZ\Publish\API\Repository\PermissionResolver; | ||
use eZ\Publish\API\Repository\Values\Content\ContentInfo; | ||
use eZ\Publish\API\Repository\Values\Content\Language; | ||
use eZ\Publish\API\Repository\Values\User\Limitation; | ||
use eZ\Publish\SPI\Limitation\Target\Version; | ||
use EzSystems\EzPlatformAdminUi\Permission\LookupLimitationsTransformer; | ||
|
||
class ContentEditTranslationChoiceLoader extends BaseChoiceLoader | ||
{ | ||
/** @var \eZ\Publish\API\Repository\LanguageService */ | ||
protected $languageService; | ||
|
||
/** @var \eZ\Publish\API\Repository\PermissionResolver */ | ||
protected $permissionResolver; | ||
|
||
/** @var string[] */ | ||
protected $languageCodes; | ||
|
||
/** @var \eZ\Publish\API\Repository\Values\Content\ContentInfo */ | ||
private $contentInfo; | ||
|
||
/** @var \EzSystems\EzPlatformAdminUi\Permission\LookupLimitationsTransformer */ | ||
private $lookupLimitationsTransformer; | ||
|
||
/** | ||
* @param \eZ\Publish\API\Repository\LanguageService $languageService | ||
* @param \eZ\Publish\API\Repository\PermissionResolver $permissionResolver | ||
* @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo | ||
* @param \EzSystems\EzPlatformAdminUi\Permission\LookupLimitationsTransformer $lookupLimitationsTransformer | ||
* @param string[] $languageCodes | ||
*/ | ||
public function __construct( | ||
LanguageService $languageService, | ||
PermissionResolver $permissionResolver, | ||
?ContentInfo $contentInfo, | ||
LookupLimitationsTransformer $lookupLimitationsTransformer, | ||
$languageCodes | ||
) { | ||
$this->languageService = $languageService; | ||
$this->permissionResolver = $permissionResolver; | ||
$this->contentInfo = $contentInfo; | ||
$this->languageCodes = $languageCodes; | ||
$this->lookupLimitationsTransformer = $lookupLimitationsTransformer; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getChoiceList(): array | ||
{ | ||
$languages = $this->languageService->loadLanguages(); | ||
$limitationLanguageCodes = []; | ||
|
||
if (!empty($this->languageCodes)) { | ||
$languages = array_filter( | ||
$languages, | ||
function (Language $language) { | ||
return \in_array($language->languageCode, $this->languageCodes, true); | ||
} | ||
); | ||
} | ||
$languagesCodes = array_column($languages, 'languageCode'); | ||
if (null !== $this->contentInfo) { | ||
$lookupLimitations = $this->permissionResolver->lookupLimitations( | ||
'content', | ||
'edit', | ||
$this->contentInfo, | ||
[(new Version())->translateToAnyLanguageOf($languagesCodes)], | ||
[Limitation\TranslationLimitation::IDENTIFIER] | ||
); | ||
|
||
$limitationLanguageCodes = $this->lookupLimitationsTransformer->getFlattenedLimitationsValues($lookupLimitations); | ||
} | ||
|
||
if (!empty($limitationLanguageCodes)) { | ||
$languages = array_filter( | ||
$languages, | ||
function (Language $language) use ($limitationLanguageCodes) { | ||
return \in_array($language->languageCode, $limitationLanguageCodes, true); | ||
} | ||
); | ||
} | ||
|
||
return $languages; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.