From d82c9cc9a70b495ca9d0d93b9789c2aa20609281 Mon Sep 17 00:00:00 2001 From: LenaertsJ Date: Wed, 8 Oct 2025 11:05:22 +0000 Subject: [PATCH] =?UTF-8?q?Resolve=20"Ajouter=20un=20bandeau=20qui=20perme?= =?UTF-8?q?t=20de=20distinguer=20les=20diff=C3=A9rents=20environnements"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unreleased/Feature-20251007-101949.yaml | 6 ++ config/packages/chill.yaml | 7 ++ .../ChillMainExtension.php | 6 ++ .../DependencyInjection/Configuration.php | 14 +++ .../views/Layout/_top_banner.html.twig | 17 ++++ .../Resources/views/layout.html.twig | 4 + .../DependencyInjection/ConfigurationTest.php | 98 +++++++++++++++++++ 7 files changed, 152 insertions(+) create mode 100644 .changes/unreleased/Feature-20251007-101949.yaml create mode 100644 src/Bundle/ChillMainBundle/Resources/views/Layout/_top_banner.html.twig create mode 100644 src/Bundle/ChillMainBundle/Tests/DependencyInjection/ConfigurationTest.php diff --git a/.changes/unreleased/Feature-20251007-101949.yaml b/.changes/unreleased/Feature-20251007-101949.yaml new file mode 100644 index 000000000..a0ba84124 --- /dev/null +++ b/.changes/unreleased/Feature-20251007-101949.yaml @@ -0,0 +1,6 @@ +kind: Feature +body: Create environment banner that can be activated and configured depending on the image deployed +time: 2025-10-07T10:19:49.784462956+02:00 +custom: + Issue: "423" + SchemaChange: No schema change diff --git a/config/packages/chill.yaml b/config/packages/chill.yaml index 6ed6b6984..e5974a6bc 100644 --- a/config/packages/chill.yaml +++ b/config/packages/chill.yaml @@ -1,6 +1,13 @@ chill_main: available_languages: [ '%env(resolve:LOCALE)%', 'en' ] available_countries: ['BE', 'FR'] + top_banner: + visible: true + text: + fr: 'Vous travaillez actuellement avec la version de PRÉ-PRODUCTION.' + nl: 'Je werkt momenteel in de PRE-PRODUCTIE versie' + color: '#353535' + background_color: '#d8bb48' notifications: from_email: '%env(resolve:NOTIFICATION_FROM_EMAIL)%' from_name: '%env(resolve:NOTIFICATION_FROM_NAME)%' diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php index 70f0df071..ebb28d2e7 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php @@ -205,6 +205,11 @@ class ChillMainExtension extends Extension implements [] ); + $container->setParameter( + 'chill_main.top_banner', + $config['top_banner'] ?? [] + ); + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config')); $loader->load('services.yaml'); $loader->load('services/doctrine.yaml'); @@ -250,6 +255,7 @@ class ChillMainExtension extends Extension implements 'name' => $config['installation_name'], ], 'available_languages' => $config['available_languages'], 'add_address' => $config['add_address'], + 'chill_main_config' => $config, ], 'form_themes' => ['@ChillMain/Form/fields.html.twig'], ]; diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php index 6625488dd..a3247d88e 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php @@ -168,6 +168,20 @@ class Configuration implements ConfigurationInterface ->end() ->end() ->end() + ->arrayNode('top_banner') + ->canBeUnset() + ->children() + ->booleanNode('visible') + ->defaultFalse() + ->end() + ->arrayNode('text') + ->useAttributeAsKey('lang') + ->scalarPrototype()->end() + ->end() // end of text + ->scalarNode('color')->defaultNull()->end() + ->scalarNode('background_color')->defaultNull()->end() + ->end() // end of top_banner children + ->end() // end of top_banner ->arrayNode('widgets') ->canBeEnabled() ->canBeUnset() diff --git a/src/Bundle/ChillMainBundle/Resources/views/Layout/_top_banner.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Layout/_top_banner.html.twig new file mode 100644 index 000000000..0ad81cce1 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/views/Layout/_top_banner.html.twig @@ -0,0 +1,17 @@ +{% if chill_main_config.top_banner is defined and chill_main_config.top_banner.text is defined %} + {% set banner_text = '' %} + {% set current_locale = app.request.locale %} + + {% if chill_main_config.top_banner.text[current_locale] is defined %} + {% set banner_text = chill_main_config.top_banner.text[current_locale] %} + {% else %} + {% set banner_text = chill_main_config.top_banner.text|first %} + {% endif %} + + {% if banner_text %} +
+ {{ banner_text }} +
+ {% endif %} +{% endif %} diff --git a/src/Bundle/ChillMainBundle/Resources/views/layout.html.twig b/src/Bundle/ChillMainBundle/Resources/views/layout.html.twig index 343c12eea..0ff39c8d9 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/layout.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/layout.html.twig @@ -26,6 +26,10 @@ + {% if chill_main_config.top_banner is defined and chill_main_config.top_banner.visible is true %} + {{ include('@ChillMain/Layout/_top_banner.html.twig') }} + {% endif %} + {% if responsive_debug is defined and responsive_debug == 1 %} {{ include('@ChillMain/Layout/_debug.html.twig') }} {% endif %} diff --git a/src/Bundle/ChillMainBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Bundle/ChillMainBundle/Tests/DependencyInjection/ConfigurationTest.php new file mode 100644 index 000000000..27f4db512 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -0,0 +1,98 @@ + [ + 'top_banner' => [ + 'text' => [ + 'fr' => 'Vous travaillez actuellement avec la version de pré-production de Chill.', + 'nl' => 'Je werkte momenteel in de pré-productie versie van Chill.', + ], + 'color' => 'white', + 'background-color' => 'red', + ], + ], + ]; + + $processedConfig = $processor->processConfiguration($configuration, $config); + + self::assertArrayHasKey('top_banner', $processedConfig); + self::assertArrayHasKey('text', $processedConfig['top_banner']); + self::assertArrayHasKey('fr', $processedConfig['top_banner']['text']); + self::assertArrayHasKey('nl', $processedConfig['top_banner']['text']); + self::assertSame('white', $processedConfig['top_banner']['color']); + self::assertSame('red', $processedConfig['top_banner']['background_color']); + } + + public function testTopBannerConfigurationOptional(): void + { + $containerBuilder = new ContainerBuilder(); + $configuration = new Configuration([], $containerBuilder); + $processor = new Processor(); + + // Test without top_banner configuration + $config = [ + 'chill_main' => [], + ]; + + $processedConfig = $processor->processConfiguration($configuration, $config); + + // top_banner should not be present when not configured + self::assertArrayNotHasKey('top_banner', $processedConfig); + } + + public function testTopBannerWithMinimalConfiguration(): void + { + $containerBuilder = new ContainerBuilder(); + $configuration = new Configuration([], $containerBuilder); + $processor = new Processor(); + + // Test with minimal top_banner configuration (only text) + $config = [ + 'chill_main' => [ + 'top_banner' => [ + 'text' => [ + 'fr' => 'Test message', + ], + ], + ], + ]; + + $processedConfig = $processor->processConfiguration($configuration, $config); + + self::assertArrayHasKey('top_banner', $processedConfig); + self::assertArrayHasKey('text', $processedConfig['top_banner']); + self::assertSame('Test message', $processedConfig['top_banner']['text']['fr']); + self::assertNull($processedConfig['top_banner']['color']); + self::assertNull($processedConfig['top_banner']['background_color']); + } +}