Skip to content

Commit

Permalink
IBX-4452: Deprecated Policy and Limitation TranslationExtractors (#662)
Browse files Browse the repository at this point in the history
  • Loading branch information
kisztof authored Dec 27, 2022
1 parent f9a1d27 commit 819bea7
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 871 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"require": {
"php": "^7.4 || ^8.0",
"ext-json": "*",
"symfony/deprecation-contracts": "^2.5",
"symfony/http-foundation": "^5.0",
"symfony/security-core": "^5.0",
"symfony/security-http": "^5.0",
Expand Down
2 changes: 2 additions & 0 deletions src/bundle/Resources/config/services/translation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ services:
- { name: jms_translation.file_visitor }

Ibexa\AdminUi\Translation\Extractor\PolicyTranslationExtractor:
deprecated: 'Since ibexa/admin-ui 4.4: The "%service_id%" service is deprecated, will be removed in 5.0'
arguments:
- '%ibexa.api.role.policy_map%'
tags:
Expand All @@ -19,6 +20,7 @@ services:
- { name: jms_translation.extractor, alias: ez_location_sorting }

Ibexa\AdminUi\Translation\Extractor\LimitationTranslationExtractor:
deprecated: 'Since ibexa/admin-ui 4.4: The "%service_id%" service is deprecated, will be removed in 5.0'
arguments:
- '%ibexa.api.role.policy_map%'
tags:
Expand Down
850 changes: 0 additions & 850 deletions src/bundle/Resources/translations/forms.en.xliff

Large diffs are not rendered by default.

17 changes: 11 additions & 6 deletions src/lib/Form/Type/Policy/PolicyChoiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace Ibexa\AdminUi\Form\Type\Policy;

use Ibexa\AdminUi\Translation\Extractor\PolicyTranslationExtractor;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
Expand All @@ -18,6 +17,12 @@

class PolicyChoiceType extends AbstractType
{
public const MESSAGE_DOMAIN = 'forms';
public const MESSAGE_ID_PREFIX = 'role.policy.';
public const ALL_MODULES = 'all_modules';
public const ALL_FUNCTIONS = 'all_functions';
public const ALL_MODULES_ALL_FUNCTIONS = 'all_modules_all_functions';

/** @var array */
private $policyChoices;

Expand Down Expand Up @@ -94,20 +99,20 @@ public function getParent(): ?string
private function buildPolicyChoicesFromMap(array $policyMap): array
{
$policyChoices = [
PolicyTranslationExtractor::MESSAGE_ID_PREFIX . PolicyTranslationExtractor::ALL_MODULES => [
PolicyTranslationExtractor::MESSAGE_ID_PREFIX . PolicyTranslationExtractor::ALL_MODULES_ALL_FUNCTIONS => '*|*',
self::MESSAGE_ID_PREFIX . self::ALL_MODULES => [
self::MESSAGE_ID_PREFIX . self::ALL_MODULES_ALL_FUNCTIONS => '*|*',
],
];

foreach ($policyMap as $module => $functionList) {
$moduleKey = PolicyTranslationExtractor::MESSAGE_ID_PREFIX . $module;
$moduleKey = self::MESSAGE_ID_PREFIX . $module;
// For each module, add possibility to grant access to all functions.
$policyChoices[$moduleKey] = [
$moduleKey . '.' . PolicyTranslationExtractor::ALL_FUNCTIONS => "$module|*",
$moduleKey . '.' . self::ALL_FUNCTIONS => "$module|*",
];

foreach ($functionList as $function => $limitationList) {
$moduleFunctionKey = PolicyTranslationExtractor::MESSAGE_ID_PREFIX . "{$module}.{$function}";
$moduleFunctionKey = self::MESSAGE_ID_PREFIX . "{$module}.{$function}";
$policyChoices[$moduleKey][$moduleFunctionKey] = "$module|$function";
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Limitation/Mapper/ChangeOwnerLimitationMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

use Ibexa\AdminUi\Limitation\LimitationFormMapperInterface;
use Ibexa\AdminUi\Limitation\LimitationValueMapperInterface;
use Ibexa\AdminUi\Translation\Extractor\LimitationTranslationExtractor;
use Ibexa\Contracts\Core\Repository\Values\User\Limitation;
use Ibexa\Contracts\Core\Repository\Values\User\Limitation\ChangeOwnerLimitation;
use Ibexa\Core\Limitation\LimitationIdentifierToLabelConverter;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
Expand Down Expand Up @@ -43,7 +43,7 @@ public function mapLimitationForm(FormInterface $form, Limitation $data): void
'multiple' => true,
'expanded' => false,
'required' => false,
'label' => LimitationTranslationExtractor::identifierToLabel($data->getIdentifier()),
'label' => LimitationIdentifierToLabelConverter::convert($data->getIdentifier()),
'choices' => array_flip($this->getSelectionChoices()),
];

Expand Down
4 changes: 2 additions & 2 deletions src/lib/Limitation/Mapper/MultipleSelectionBasedMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
namespace Ibexa\AdminUi\Limitation\Mapper;

use Ibexa\AdminUi\Limitation\LimitationFormMapperInterface;
use Ibexa\AdminUi\Translation\Extractor\LimitationTranslationExtractor;
use Ibexa\Contracts\Core\Repository\Values\User\Limitation;
use Ibexa\Core\Limitation\LimitationIdentifierToLabelConverter;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormInterface;

Expand All @@ -28,7 +28,7 @@ public function mapLimitationForm(FormInterface $form, Limitation $data)
{
$options = $this->getChoiceFieldOptions() + [
'multiple' => true,
'label' => LimitationTranslationExtractor::identifierToLabel($data->getIdentifier()),
'label' => LimitationIdentifierToLabelConverter::convert($data->getIdentifier()),
'required' => false,
];
$choices = $this->getSelectionChoices();
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Limitation/Mapper/UDWBasedMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
use Ibexa\AdminUi\Form\DataTransformer\UDWBasedValueViewTransformer;
use Ibexa\AdminUi\Limitation\LimitationFormMapperInterface;
use Ibexa\AdminUi\Limitation\LimitationValueMapperInterface;
use Ibexa\AdminUi\Translation\Extractor\LimitationTranslationExtractor;
use Ibexa\Contracts\Core\Repository\LocationService;
use Ibexa\Contracts\Core\Repository\SearchService;
use Ibexa\Contracts\Core\Repository\Values\Content\LocationQuery;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Ancestor;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\SortClause\Location\Path;
use Ibexa\Contracts\Core\Repository\Values\User\Limitation;
use Ibexa\Core\Limitation\LimitationIdentifierToLabelConverter;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormInterface;

Expand Down Expand Up @@ -71,7 +71,7 @@ public function mapLimitationForm(FormInterface $form, Limitation $data)
->createBuilder()
->create('limitationValues', HiddenType::class, [
'required' => false,
'label' => LimitationTranslationExtractor::identifierToLabel($data->getIdentifier()),
'label' => LimitationIdentifierToLabelConverter::convert($data->getIdentifier()),
])
->addViewTransformer(new UDWBasedValueViewTransformer($this->locationService))
->addModelTransformer(new UDWBasedValueModelTransformer($this->locationService))
Expand Down
6 changes: 4 additions & 2 deletions src/lib/Limitation/Mapper/UserPermissionsLimitationMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

use Ibexa\AdminUi\Limitation\LimitationFormMapperInterface;
use Ibexa\AdminUi\Limitation\LimitationValueMapperInterface;
use Ibexa\AdminUi\Translation\Extractor\LimitationTranslationExtractor;
use Ibexa\Contracts\Core\Repository\Repository;
use Ibexa\Contracts\Core\Repository\RoleService;
use Ibexa\Contracts\Core\Repository\SearchService;
use Ibexa\Contracts\Core\Repository\UserService;
use Ibexa\Contracts\Core\Repository\Values\User\Limitation;
use Ibexa\Core\Limitation\LimitationIdentifierToLabelConverter;
use Ibexa\User\Form\ChoiceList\Loader\UserGroupsChoiceLoader;
use Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
Expand Down Expand Up @@ -55,7 +55,9 @@ public function mapLimitationForm(FormInterface $form, Limitation $data)
->create(
'limitationValues',
FormType::class,
['label' => LimitationTranslationExtractor::identifierToLabel($data->getIdentifier())]
[
'label' => LimitationIdentifierToLabelConverter::convert($data->getIdentifier()),
]
)
->setAutoInitialize(false)
->getForm();
Expand Down
16 changes: 14 additions & 2 deletions src/lib/Translation/Extractor/LimitationTranslationExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@

namespace Ibexa\AdminUi\Translation\Extractor;

use Ibexa\Core\Limitation\LimitationIdentifierToLabelConverter;
use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Model\MessageCatalogue;
use JMS\TranslationBundle\Translation\ExtractorInterface;

/**
* Generates translation strings for limitation types.
*
* @deprecated Since ibexa/admin-ui 4.4: The "LimitationTranslationExtractor" class is deprecated, will be removed in 5.0.
*/
class LimitationTranslationExtractor implements ExtractorInterface
{
public const MESSAGE_DOMAIN = 'ezplatform_content_forms_policies';
public const MESSAGE_ID_PREFIX = 'policy.limitation.identifier.';
public const MESSAGE_ID_PREFIX = LimitationIdentifierToLabelConverter::MESSAGE_ID_PREFIX;

/**
* @var array
Expand All @@ -33,8 +36,13 @@ public function __construct(array $policyMap)
$this->policyMap = $policyMap;
}

/**
* @deprecated Since ibexa/admin-ui 4.4: The method "LimitationTranslationExtractor::extract()" method is deprecated, will be removed in 5.0.
*/
public function extract()
{
trigger_deprecation('ibexa/admin', '4.4', 'The %s() method is deprecated, will be removed in 5.0.', __METHOD__);

$catalogue = new MessageCatalogue();

foreach ($this->getLimitationTypes() as $limitationType) {
Expand All @@ -56,11 +64,15 @@ public function extract()
/**
* @param string $limitationIdentifier
*
* @deprecated Since ibexa/admin-ui 4.4: The method "LimitationTranslationExtractor::identifierToLabel()" method is deprecated, will be removed in 5.0. Use Ibexa\Core\Limitation\LimitationIdentifierToLabelConverter::convert() instead.
*
* @return string
*/
public static function identifierToLabel(string $limitationIdentifier): string
{
return self::MESSAGE_ID_PREFIX . strtolower($limitationIdentifier);
trigger_deprecation('ibexa/admin', '4.4', 'The %s() method is deprecated, will be removed in 5.0. Use %s::convert() instead.', __METHOD__, LimitationIdentifierToLabelConverter::class);

return LimitationIdentifierToLabelConverter::convert($limitationIdentifier);
}

/**
Expand Down
17 changes: 12 additions & 5 deletions src/lib/Translation/Extractor/PolicyTranslationExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@

namespace Ibexa\AdminUi\Translation\Extractor;

use Ibexa\AdminUi\Form\Type\Policy\PolicyChoiceType;
use JMS\TranslationBundle\Model\Message\XliffMessage;
use JMS\TranslationBundle\Model\MessageCatalogue;
use JMS\TranslationBundle\Translation\ExtractorInterface;

/**
* Generates translation strings for limitation types.
*
* @deprecated Since ibexa/admin-ui 4.4: The "PolicyTranslationExtractor" class is deprecated, will be removed in 5.0.
*/
class PolicyTranslationExtractor implements ExtractorInterface
{
public const MESSAGE_DOMAIN = 'forms';
public const MESSAGE_ID_PREFIX = 'role.policy.';
public const ALL_MODULES = 'all_modules';
public const ALL_FUNCTIONS = 'all_functions';
public const ALL_MODULES_ALL_FUNCTIONS = 'all_modules_all_functions';
public const MESSAGE_DOMAIN = PolicyChoiceType::MESSAGE_DOMAIN;
public const MESSAGE_ID_PREFIX = PolicyChoiceType::MESSAGE_ID_PREFIX;
public const ALL_MODULES = PolicyChoiceType::ALL_MODULES;
public const ALL_FUNCTIONS = PolicyChoiceType::ALL_FUNCTIONS;
public const ALL_MODULES_ALL_FUNCTIONS = PolicyChoiceType::ALL_MODULES_ALL_FUNCTIONS;

/** @var array */
private $policyMap;
Expand All @@ -36,9 +39,13 @@ public function __construct(array $policyMap)

/**
* @return \JMS\TranslationBundle\Model\MessageCatalogue
*
* @deprecated Since ibexa/admin-ui 4.4: The method "PolicyTranslationExtractor::extract()" method is deprecated, will be removed in 5.0.
*/
public function extract(): MessageCatalogue
{
trigger_deprecation('ibexa/admin', '4.4', 'The %s() method is deprecated, will be removed in 5.0.', __METHOD__);

$catalogue = new MessageCatalogue();

$catalogue->add($this->createMessage(self::ALL_MODULES, 'All modules'));
Expand Down

0 comments on commit 819bea7

Please sign in to comment.