Skip to content

Commit

Permalink
IBX-6939: As the User I want to change mode in User settings (#998)
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
3 people authored Nov 23, 2023
1 parent 973b866 commit 9c42a75
Show file tree
Hide file tree
Showing 8 changed files with 334 additions and 0 deletions.
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]
);
}
}
1 change: 1 addition & 0 deletions src/bundle/IbexaAdminUiBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ private function getConfigParsers(): array
new Parser\SubtreePath(),
new Parser\LimitationValueTemplates(),
new Parser\Assets(),
new Parser\AdminUiParser(),
];
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/bundle/Resources/config/default_parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,5 @@ parameters:
ibexa.io.multifile_upload.max_file_size: 5242880

ibexa.admin_ui.content_tree.node_factory.max_location_ids_in_single_aggregation: 100

ibexa.site_access.config.default.admin_ui.default_user_mode: '1'
9 changes: 9 additions & 0 deletions src/bundle/Resources/config/services/user_settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,12 @@ services:
tags:
- { name: ibexa.user.setting.value, identifier: in_context_translation, group: location, priority: 60 }
- { name: ibexa.user.setting.mapper.form, identifier: in_context_translation }

Ibexa\AdminUi\UserSetting\Group\UserModeGroup:
tags:
- { name: ibexa.user.setting.group, identifier: mode, priority: -10 }

Ibexa\AdminUi\UserSetting\UserMode:
tags:
- { name: ibexa.user.setting.value, identifier: user_mode, group: mode, priority: 10 }
- { name: ibexa.user.setting.mapper.form, identifier: user_mode }
50 changes: 50 additions & 0 deletions src/bundle/Resources/translations/ibexa_user_settings.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
<target state="new">Date and Time will be displayed in this format:</target>
<note>key: settings.datetime_format.preview_label</note>
</trans-unit>
<trans-unit id="4030d22c6edcd7185a9584ae76a5948aedaa1594" resname="settings.group.mode.name">
<source>Mode</source>
<target state="new">Mode</target>
<note>key: settings.group.mode.name</note>
</trans-unit>
<trans-unit id="3e6a40d77072c330caa54630a0ee78371e3b5bcc" resname="settings.in_context_translation.value.description">
<source>Toggle In-Context translation feature</source>
<target state="new">Toggle In-Context translation feature</target>
Expand All @@ -76,6 +81,51 @@
<target state="new">In-Context translation</target>
<note>key: settings.in_context_translation.value.title</note>
</trans-unit>
<trans-unit id="1908a078c655a123c1e03b2b8dbe39240ad9d7f5" resname="user.setting.mode.description">
<source>Mode</source>
<target state="new">Mode</target>
<note>key: user.setting.mode.description</note>
</trans-unit>
<trans-unit id="581ee2faad6bfe1d4af2e60bf3912162bd57aedd" resname="user.setting.mode.expert">
<source>Expert</source>
<target state="new">Expert</target>
<note>key: user.setting.mode.expert</note>
</trans-unit>
<trans-unit id="7bbfadd84e2abbfb1923b38c4b27f14fe4585c55" resname="user.setting.mode.help">
<source><![CDATA[<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>]]></source>
<target state="new"><![CDATA[<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>]]></target>
<note>key: user.setting.mode.help</note>
</trans-unit>
<trans-unit id="7036f294d389a7a41226580ce5f0c62bc1a85c21" resname="user.setting.mode.name">
<source>Mode</source>
<target state="new">Mode</target>
<note>key: user.setting.mode.name</note>
</trans-unit>
<trans-unit id="3d0f321c83d4cf337389cbd0a0d36dc218516750" resname="user.setting.mode.smart">
<source>Smart</source>
<target state="new">Smart</target>
<note>key: user.setting.mode.smart</note>
</trans-unit>
</body>
</file>
</xliff>
33 changes: 33 additions & 0 deletions src/lib/Form/Type/User/UserModeChoiceType.php
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;
}
}
44 changes: 44 additions & 0 deletions src/lib/UserSetting/Group/UserModeGroup.php
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 '';
}
}
113 changes: 113 additions & 0 deletions src/lib/UserSetting/UserMode.php
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'),
];
}
}

0 comments on commit 9c42a75

Please sign in to comment.