From fff9a5b95fe125892ace89981e45943ae2175a5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 20 Mar 2026 11:59:05 +0000 Subject: [PATCH] Add configurable homepage tabs with validation for default tab inclusion --- config/packages/chill.yaml | 3 +++ .../DependencyInjection/ChillMainExtension.php | 13 ++++++++++++- .../DependencyInjection/Configuration.php | 11 +++++++++++ .../ChillMainBundle/Resources/public/types.ts | 10 ++++++++-- .../Resources/public/vuejs/HomepageWidget/App.vue | 5 +++-- .../Resources/views/Homepage/index.html.twig | 5 +---- .../translations/messages+intl-icu.fr.yaml | 2 +- 7 files changed, 39 insertions(+), 10 deletions(-) diff --git a/config/packages/chill.yaml b/config/packages/chill.yaml index 26f91feb5..121c317c9 100644 --- a/config/packages/chill.yaml +++ b/config/packages/chill.yaml @@ -34,6 +34,9 @@ chill_main: x: '%env(float:ADD_ADDRESS_MAP_CENTER_X)%' y: '%env(float:ADD_ADDRESS_MAP_CENTER_Y)%' z: '%env(float:ADD_ADDRESS_MAP_CENTER_Z)%' + homepage: + default_tab: 'MyCustoms' + display_tabs: ['MyCustoms', 'MyNotifications', 'MyAccompanyingCourses', 'MyEvaluations', 'MyTasks', 'MyWorkflows', 'MyTickets'] when@test: chill_main: diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php index ebb28d2e7..856c0ae09 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php @@ -84,6 +84,7 @@ use Chill\MainBundle\Security\Authorization\ChillExportVoter; use Chill\MainBundle\Security\Authorization\EntityWorkflowVoter; use Misd\PhoneNumberBundle\Doctrine\DBAL\Types\PhoneNumberType; use Ramsey\Uuid\Doctrine\UuidType; +use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; @@ -210,6 +211,15 @@ class ChillMainExtension extends Extension implements $config['top_banner'] ?? [] ); + if (!in_array($config['homepage']['default_tab'], $config['homepage']['display_tabs'], true)) { + throw new InvalidConfigurationException('The chill_main.homepage.default_tab must be included in chill_main.homepage.display_tabs'); + } + + $container->setParameter( + 'chill_main.homepage', + $config['homepage'] + ); + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config')); $loader->load('services.yaml'); $loader->load('services/doctrine.yaml'); @@ -241,7 +251,7 @@ class ChillMainExtension extends Extension implements // $this->configureSms($config['short_messages'], $container, $loader); } - public function prepend(ContainerBuilder $container) + public function prepend(ContainerBuilder $container): void { $this->prependNotifierTexterWithLegacyData($container); @@ -256,6 +266,7 @@ class ChillMainExtension extends Extension implements 'available_languages' => $config['available_languages'], 'add_address' => $config['add_address'], 'chill_main_config' => $config, + 'homepage_widget_config' => $config['homepage'], ], 'form_themes' => ['@ChillMain/Form/fields.html.twig'], ]; diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php index a3247d88e..712ebc004 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php @@ -325,6 +325,17 @@ class Configuration implements ConfigurationInterface ->end() ->end(); + /* @phpstan-ignore-next-line */ + $rootNode->children() + ->arrayNode('homepage')->addDefaultsIfNotSet() + ->children() + ->scalarNode('default_tab')->defaultValue('MyCustoms')->end() + ->arrayNode('display_tabs') + ->info('List of tabs to display on the homepage.') + ->defaultValue(['MyCustoms', 'MyNotifications', 'MyAccompanyingCourses', 'MyEvaluations', 'MyTasks', 'MyWorkflows']) + ->scalarPrototype()->end() + ->end(); + return $treeBuilder; } } diff --git a/src/Bundle/ChillMainBundle/Resources/public/types.ts b/src/Bundle/ChillMainBundle/Resources/public/types.ts index a28204936..3023ddd98 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/types.ts +++ b/src/Bundle/ChillMainBundle/Resources/public/types.ts @@ -486,9 +486,15 @@ export enum HomepageTabs { MyWorkflows, } +/** + * The configuration for homepage config. + * + * This config comes from configuration (see ChillMainBundle/DependencyInjection/Configuration or chill_main.homepage configuration + * in packages/config files). It goes through a twig globals, and is displayed in the homepage. + */ export interface HomepageConfig { - defaultTab: HomepageTabs; - displayTabs: HomepageTabs[]; + default_tab: HomepageTabs; + display_tabs: HomepageTabs[]; } export interface TabDefinition { diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/App.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/App.vue index a494cfea8..3ec07682b 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/App.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/App.vue @@ -123,7 +123,7 @@ const tabDefinitions: TabDefinition[] = [ const displayedTabs = computed(() => { const tabs = [] as TabDefinition[]; - for (const tabEnum of homepageConfig.value.displayTabs) { + for (const tabEnum of homepageConfig.value.display_tabs) { const def = tabDefinitions.find( (t) => t.key === Number(HomepageTabs[tabEnum]), ); @@ -132,7 +132,7 @@ const displayedTabs = computed(() => { return tabs.filter(Boolean); }); -const activeTab = ref(Number(HomepageTabs[homepageConfig.value.defaultTab])); +const activeTab = ref(Number(HomepageTabs[homepageConfig.value.default_tab])); const loading = computed(() => store.state.loading); @@ -152,5 +152,6 @@ onMounted(() => { diff --git a/src/Bundle/ChillMainBundle/Resources/views/Homepage/index.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Homepage/index.html.twig index 290fd91ef..27214da68 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Homepage/index.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Homepage/index.html.twig @@ -12,10 +12,7 @@ {% block js %} {{ encore_entry_script_tags('page_homepage_widget') }} diff --git a/src/Bundle/ChillMainBundle/translations/messages+intl-icu.fr.yaml b/src/Bundle/ChillMainBundle/translations/messages+intl-icu.fr.yaml index fc8c7a48e..66c134c53 100644 --- a/src/Bundle/ChillMainBundle/translations/messages+intl-icu.fr.yaml +++ b/src/Bundle/ChillMainBundle/translations/messages+intl-icu.fr.yaml @@ -190,7 +190,7 @@ my_tasks.description_alert: "Liste des tâches auxquelles je suis assigné et do my_tasks.description_warning: "Liste des tâches auxquelles je suis assigné et dont la date d'échéance est dépassée." my_accompanying_courses.tab: "Mes nouveaux parcours" my_accompanying_courses.description: "Liste des parcours d'accompagnement que l'on vient de m'attribuer depuis moins de 15 jours." -my_notifications.tab: "Mes nouvelles notifications" +my_notifications.tab: "Mes notifications" my_notifications.description: "Liste des notifications reçues et non lues." my_workflows.tab: "Mes workflows" my_workflows.description: "Liste des workflows en attente d'une action."