-
Notifications
You must be signed in to change notification settings - Fork 18
IBX-6939: As the User I want to change mode in User settings #998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0d1789f
Added user mode settings
kisztof 412681f
Apply suggestions from code review
kisztof 5f4bbea
Improvements
kisztof 890bcc7
Improvements
kisztof 79d45c0
Code review improvements
kisztof cdd016e
Translation improvements
kisztof 2606fd9
Changed AdminUIParser to AdminUiParser
kisztof 9e9b904
Added missing parameter
kisztof 17ef479
Fixed choice loader
kisztof 42f0416
Removed yoda codding
kisztof f951110
Hardcoded translation domain
kisztof a5fb295
Smart/Expert insted of Expert/Smart in choice
kisztof a804f6b
Fixed default value
kisztof File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
src/bundle/DependencyInjection/Configuration/Parser/AdminUiParser.php
This file contains hidden or 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,82 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ibexa\Bundle\AdminUi\DependencyInjection\Configuration\Parser; | ||
|
|
||
| use Ibexa\AdminUi\UserSetting\UserMode; | ||
| use Ibexa\Bundle\Core\DependencyInjection\Configuration\AbstractParser; | ||
| use Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface; | ||
| use Symfony\Component\Config\Definition\Builder\NodeBuilder; | ||
|
|
||
| /** | ||
| * Configuration parser for user modes. | ||
| * | ||
| * ```yaml | ||
| * ibexa: | ||
| * system: | ||
| * default: # configuration per siteaccess or siteaccess group | ||
| * admin_ui: | ||
| * default_user_mode: smart | ||
| * ``` | ||
| */ | ||
| final class AdminUiParser extends AbstractParser | ||
| { | ||
| private const MODES = [ | ||
| 'expert' => UserMode::EXPERT, | ||
| 'smart' => UserMode::SMART, | ||
| ]; | ||
|
|
||
| /** | ||
| * @param array<string, mixed> $scopeSettings | ||
| */ | ||
| public function mapConfig( | ||
| array &$scopeSettings, | ||
| $currentScope, | ||
| ContextualizerInterface $contextualizer | ||
| ): void { | ||
| if (empty($scopeSettings['admin_ui'])) { | ||
| return; | ||
| } | ||
|
|
||
| $settings = $scopeSettings['admin_ui']; | ||
|
|
||
| $this->addUserModeParameters($settings, $currentScope, $contextualizer); | ||
| } | ||
|
|
||
| public function addSemanticConfig(NodeBuilder $nodeBuilder): void | ||
| { | ||
| $root = $nodeBuilder->arrayNode('admin_ui'); | ||
| $root->children() | ||
| ->enumNode('default_user_mode') | ||
| ->info('Default user mode setting') | ||
| ->values(['smart', 'expert']) | ||
| ->end() | ||
| ->end(); | ||
| } | ||
|
|
||
| /** | ||
| * @param array<string, mixed> $settings | ||
| */ | ||
| private function addUserModeParameters( | ||
| array $settings, | ||
| string $currentScope, | ||
| ContextualizerInterface $contextualizer | ||
| ): void { | ||
| $userMode = $settings['default_user_mode']; | ||
|
|
||
| if (false === array_key_exists($userMode, self::MODES)) { | ||
| return; | ||
| } | ||
|
|
||
| $contextualizer->setContextualParameter( | ||
| 'admin_ui.default_user_mode', | ||
| $currentScope, | ||
| self::MODES[$userMode] | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,46 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ibexa\AdminUi\Form\Type\User; | ||
|
|
||
| use Ibexa\AdminUi\UserSetting\UserMode; | ||
| use Symfony\Component\Form\AbstractType; | ||
| use Symfony\Component\Form\ChoiceList\ChoiceList; | ||
| use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||
| use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
|
||
| final class UserModeChoiceType extends AbstractType | ||
| { | ||
| private const TRANSLATION_DOMAIN = 'ibexa_user_settings'; | ||
|
|
||
| public function configureOptions(OptionsResolver $resolver): void | ||
| { | ||
| $resolver->setDefaults([ | ||
| 'choice_loader' => ChoiceList::lazy($this, $this->getChoiceLoader()), | ||
kisztof marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 'translation_domain' => self::TRANSLATION_DOMAIN, | ||
| ]); | ||
| } | ||
|
|
||
| public function getParent(): string | ||
| { | ||
| return ChoiceType::class; | ||
| } | ||
|
|
||
| /** | ||
| * @phpstan-return callable(): array<string, string> | ||
| */ | ||
| private function getChoiceLoader(): callable | ||
| { | ||
| return static function (): array { | ||
| return [ | ||
| 'user.setting.mode.expert' => UserMode::EXPERT, | ||
| 'user.setting.mode.smart' => UserMode::SMART, | ||
| ]; | ||
| }; | ||
| } | ||
| } | ||
This file contains hidden or 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,44 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ibexa\AdminUi\UserSetting\Group; | ||
|
|
||
| use Ibexa\User\UserSetting\Group\AbstractGroup; | ||
| use JMS\TranslationBundle\Annotation\Desc; | ||
| use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
|
||
| final class UserModeGroup extends AbstractGroup | ||
| { | ||
| private TranslatorInterface $translator; | ||
|
|
||
| /** | ||
| * @param array<string, \Ibexa\Contracts\User\UserSetting\ValueDefinitionInterface> $values | ||
| */ | ||
| public function __construct( | ||
| TranslatorInterface $translator, | ||
| array $values = [] | ||
| ) { | ||
| $this->translator = $translator; | ||
| parent::__construct($values); | ||
| } | ||
|
|
||
| public function getName(): string | ||
| { | ||
| return $this->translator->trans( | ||
| /** @Desc("Mode") */ | ||
| 'settings.group.mode.name', | ||
| [], | ||
| 'ibexa_user_settings' | ||
| ); | ||
| } | ||
|
|
||
| public function getDescription(): string | ||
| { | ||
| return ''; | ||
| } | ||
| } |
This file contains hidden or 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,113 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ibexa\AdminUi\UserSetting; | ||
|
|
||
| use Ibexa\AdminUi\Form\Type\User\UserModeChoiceType; | ||
| use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; | ||
| use Ibexa\Contracts\User\UserSetting\FormMapperInterface; | ||
| use Ibexa\Contracts\User\UserSetting\ValueDefinitionInterface; | ||
| use JMS\TranslationBundle\Model\Message; | ||
| use JMS\TranslationBundle\Translation\TranslationContainerInterface; | ||
| use Symfony\Component\Form\FormBuilderInterface; | ||
| use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
|
||
| final class UserMode implements ValueDefinitionInterface, FormMapperInterface, TranslationContainerInterface | ||
| { | ||
| public const EXPERT = '0'; | ||
| public const SMART = '1'; | ||
|
|
||
| private TranslatorInterface $translator; | ||
|
|
||
| private ConfigResolverInterface $configResolver; | ||
|
|
||
| public function __construct( | ||
| ConfigResolverInterface $configResolver, | ||
| TranslatorInterface $translator | ||
| ) { | ||
| $this->configResolver = $configResolver; | ||
| $this->translator = $translator; | ||
| } | ||
|
|
||
| public function getName(): string | ||
| { | ||
| return $this->translator->trans( | ||
| 'user.setting.mode.name', | ||
| [], | ||
| 'ibexa_user_settings' | ||
| ); | ||
| } | ||
|
|
||
| public function getDescription(): string | ||
| { | ||
| return $this->translator->trans( | ||
| 'user.setting.mode.description', | ||
| [], | ||
| 'ibexa_user_settings' | ||
| ); | ||
| } | ||
|
|
||
| public function getDisplayValue(string $storageValue): string | ||
| { | ||
| $translationMap = [ | ||
| self::EXPERT => $this->translator->trans('user.setting.mode.expert', [], 'ibexa_user_settings'), | ||
| self::SMART => $this->translator->trans('user.setting.mode.smart', [], 'ibexa_user_settings'), | ||
| ]; | ||
|
|
||
| return $translationMap[$storageValue] ?? $storageValue; | ||
| } | ||
|
|
||
| public function getDefaultValue(): string | ||
| { | ||
| return $this->configResolver->getParameter('admin_ui.default_user_mode'); | ||
| } | ||
|
|
||
| public function mapFieldForm( | ||
| FormBuilderInterface $formBuilder, | ||
| ValueDefinitionInterface $value | ||
| ): FormBuilderInterface { | ||
| return $formBuilder->create( | ||
| 'value', | ||
| UserModeChoiceType::class, | ||
| [ | ||
| 'label' => 'user.setting.mode.name', | ||
| 'expanded' => true, | ||
| 'multiple' => false, | ||
| 'translation_domain' => 'ibexa_user_settings', | ||
| 'help' => $this->translator->trans('user.setting.mode.help', [], 'ibexa_user_settings'), | ||
| 'help_html' => true, | ||
| ] | ||
| ); | ||
| } | ||
|
|
||
| public static function getTranslationMessages(): array | ||
| { | ||
| return [ | ||
| (new Message('user.setting.mode.help', 'ibexa_user_settings')) | ||
| ->setDesc( | ||
| '<p><strong>Smart mode</strong> – A clean and intuitive interface with a simplified content | ||
| structure, designed for new and non-advanced users. Features include:</p> | ||
| <ul> | ||
| <li>Quick preview</li> | ||
| <li>Hidden Technical Details tab</li> | ||
| <li>Hidden Locations and Versions tabs in Content items</li> | ||
| </ul> | ||
| <p><strong>Expert mode</strong> – Tailored for experienced users familiar with Ibexa DXP. | ||
| Provides comprehensive insights into the technical aspects of Content structure, including:</p> | ||
| <ul> | ||
| <li>Technical Details tab</li> | ||
| <li>Location: Archived versions</li> | ||
| </ul>' | ||
| ), | ||
| (new Message('user.setting.mode.expert', 'ibexa_user_settings'))->setDesc('Expert'), | ||
| (new Message('user.setting.mode.smart', 'ibexa_user_settings'))->setDesc('Smart'), | ||
| (new Message('user.setting.mode.name', 'ibexa_user_settings'))->setDesc('Mode'), | ||
| (new Message('user.setting.mode.description', 'ibexa_user_settings'))->setDesc('Mode'), | ||
| ]; | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.