mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-14 09:19:41 +00:00
Resolve "Ajouter un bandeau qui permet de distinguer les différents environnements"
This commit is contained in:
@@ -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'],
|
||||
];
|
||||
|
@@ -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()
|
||||
|
@@ -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 %}
|
||||
<div class="top-banner w-100 text-center py-2"
|
||||
style="{% if chill_main_config.top_banner.color is defined %}color: {{ chill_main_config.top_banner.color }};{% endif %}{% if chill_main_config.top_banner.background_color is defined %}background-color: {{ chill_main_config.top_banner.background_color }};{% endif %}">
|
||||
{{ banner_text }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
@@ -26,6 +26,10 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{% 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 %}
|
||||
|
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Tests\DependencyInjection;
|
||||
|
||||
use Chill\MainBundle\DependencyInjection\Configuration;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\Definition\Processor;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
class ConfigurationTest extends TestCase
|
||||
{
|
||||
public function testTopBannerConfiguration(): void
|
||||
{
|
||||
$containerBuilder = new ContainerBuilder();
|
||||
$configuration = new Configuration([], $containerBuilder);
|
||||
$processor = new Processor();
|
||||
|
||||
// Test with top_banner configuration
|
||||
$config = [
|
||||
'chill_main' => [
|
||||
'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']);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user