-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Maciej Kobus <[email protected]> Co-authored-by: Krzysztof Słomka <[email protected]>
- Loading branch information
1 parent
973b866
commit 9c42a75
Showing
8 changed files
with
334 additions
and
0 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
src/bundle/DependencyInjection/Configuration/Parser/AdminUiParser.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,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 (!array_key_exists($userMode, self::MODES)) { | ||
return; | ||
} | ||
|
||
$contextualizer->setContextualParameter( | ||
'admin_ui.default_user_mode', | ||
$currentScope, | ||
self::MODES[$userMode] | ||
); | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?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\Extension\Core\Type\ChoiceType; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
final class UserModeChoiceType extends AbstractType | ||
{ | ||
public function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
$resolver->setDefaults([ | ||
'translation_domain' => 'ibexa_user_settings', | ||
'choices' => [ | ||
'user.setting.mode.smart' => UserMode::SMART, | ||
'user.setting.mode.expert' => UserMode::EXPERT, | ||
], | ||
]); | ||
} | ||
|
||
public function getParent(): string | ||
{ | ||
return ChoiceType::class; | ||
} | ||
} |
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,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 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'), | ||
]; | ||
} | ||
} |