Skip to content
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

EZP-30253: Reorder the "My Preferences" options under User settings #17

Merged
merged 1 commit into from
Mar 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ public function process(ContainerBuilder $container)
);
}

$registryDefinition->addMethodCall('addValueDefinition', [$tag['identifier'], new Reference($taggedServiceId)]);
$registryDefinition->addMethodCall('addValueDefinition', [
$tag['identifier'],
new Reference($taggedServiceId),
$tag['priority'] ?? 0,
]);
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/bundle/Resources/config/services/user_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,34 @@ services:
#
EzSystems\EzPlatformUser\UserSetting\Setting\Timezone:
tags:
- { name: ezplatform.admin_ui.user_setting.value, identifier: timezone }
- { name: ezplatform.admin_ui.user_setting.value, identifier: timezone, priority: 50 }
- { name: ezplatform.admin_ui.user_setting.form_mapper, identifier: timezone }

EzSystems\EzPlatformUser\UserSetting\Setting\SubitemsLimit:
arguments:
$subitemsLimit: '$subitems_module.limit$'
tags:
- { name: ezplatform.admin_ui.user_setting.value, identifier: subitems_limit }
- { name: ezplatform.admin_ui.user_setting.value, identifier: subitems_limit, priority: 20 }
- { name: ezplatform.admin_ui.user_setting.form_mapper, identifier: subitems_limit }

EzSystems\EzPlatformUser\UserSetting\Setting\CharacterCounter:
tags:
- { name: ezplatform.admin_ui.user_setting.value, identifier: character_counter }
- { name: ezplatform.admin_ui.user_setting.value, identifier: character_counter, priority: 10 }
- { name: ezplatform.admin_ui.user_setting.form_mapper, identifier: character_counter }

EzSystems\EzPlatformUser\UserSetting\Setting\FullDateTimeFormat:
tags:
- { name: ezplatform.admin_ui.user_setting.value, identifier: full_datetime_format }
- { name: ezplatform.admin_ui.user_setting.value, identifier: full_datetime_format, priority: 30 }
- { name: ezplatform.admin_ui.user_setting.form_mapper, identifier: full_datetime_format }

EzSystems\EzPlatformUser\UserSetting\Setting\ShortDateTimeFormat:
tags:
- { name: ezplatform.admin_ui.user_setting.value, identifier: short_datetime_format }
- { name: ezplatform.admin_ui.user_setting.value, identifier: short_datetime_format, priority: 40 }
- { name: ezplatform.admin_ui.user_setting.form_mapper, identifier: short_datetime_format }

EzSystems\EzPlatformUser\UserSetting\Setting\Language:
arguments:
$availableLocaleChoiceLoader: '@EzSystems\EzPlatformUser\Form\ChoiceList\Loader\AvailableLocaleChoiceLoader'
tags:
- { name: ezplatform.admin_ui.user_setting.value, identifier: language }
- { name: ezplatform.admin_ui.user_setting.value, identifier: language, priority: 60 }
- { name: ezplatform.admin_ui.user_setting.form_mapper, identifier: language }
27 changes: 19 additions & 8 deletions src/lib/UserSetting/ValueDefinitionRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,31 @@
*/
class ValueDefinitionRegistry
{
/** @var \EzSystems\EzPlatformAdminUi\UserSetting\ValueDefinitionInterface[] */
/** @var \EzSystems\EzPlatformUser\UserSetting\ValueDefinitionRegistryEntry[] */
protected $valueDefinitions;

/**
* @param \EzSystems\EzPlatformAdminUi\UserSetting\ValueDefinitionInterface[] $valueDefinitions
* @param \EzSystems\EzPlatformUser\UserSetting\ValueDefinitionRegistryEntry[] $valueDefinitions
*/
public function __construct(array $valueDefinitions = [])
{
$this->valueDefinitions = $valueDefinitions;
$this->valueDefinitions = [];
foreach ($valueDefinitions as $identifier => $valueDefinition) {
$valueDefinitions[$identifier] = new ValueDefinitionRegistryEntry($valueDefinition);
}
}

/**
* @param string $identifier
* @param \EzSystems\EzPlatformUser\UserSetting\ValueDefinitionInterface $valueDefinition
* @param AdminUiUserSettings\ValueDefinitionInterface $valueDefinition
* @param int $priority
*/
public function addValueDefinition(
string $identifier,
AdminUiUserSettings\ValueDefinitionInterface $valueDefinition
AdminUiUserSettings\ValueDefinitionInterface $valueDefinition,
int $priority = 0
): void {
$this->valueDefinitions[$identifier] = $valueDefinition;
$this->valueDefinitions[$identifier] = new ValueDefinitionRegistryEntry($valueDefinition, $priority);
}

/**
Expand All @@ -54,7 +59,7 @@ public function getValueDefinition(string $identifier): AdminUiUserSettings\Valu
);
}

return $this->valueDefinitions[$identifier];
return $this->valueDefinitions[$identifier]->getDefinition();
}

/**
Expand All @@ -72,6 +77,12 @@ public function hasValueDefinition(string $identifier): bool
*/
public function getValueDefinitions(): array
{
return $this->valueDefinitions;
uasort($this->valueDefinitions, function (ValueDefinitionRegistryEntry $a, ValueDefinitionRegistryEntry $b) {
return $b->getPriority() <=> $a->getPriority();
});

return array_map(function (ValueDefinitionRegistryEntry $entry) {
return $entry->getDefinition();
}, $this->valueDefinitions);
}
}
47 changes: 47 additions & 0 deletions src/lib/UserSetting/ValueDefinitionRegistryEntry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?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\EzPlatformUser\UserSetting;

/**
* @internal
*/
final class ValueDefinitionRegistryEntry
{
/** @var \EzSystems\EzPlatformAdminUi\UserSetting\ValueDefinitionInterface */
private $definition;

/** @var int */
private $priority;

/**
* @param \EzSystems\EzPlatformUser\UserSetting\ValueDefinitionInterface $definition
* @param int $priority
*/
public function __construct(ValueDefinitionInterface $definition, int $priority = 0)
{
$this->definition = $definition;
$this->priority = $priority;
}

/**
* @return \EzSystems\EzPlatformUser\UserSetting\ValueDefinitionInterface
*/
public function getDefinition(): ValueDefinitionInterface
{
return $this->definition;
}

/**
* @return int
*/
public function getPriority(): int
{
return $this->priority;
}
}