Skip to content

Commit

Permalink
Remove custom environment handling
Browse files Browse the repository at this point in the history
Symfony environments should be used instead.
  • Loading branch information
jdreesen committed May 8, 2024
1 parent 1582cd6 commit fa7e3d7
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 98 deletions.
56 changes: 28 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Pimcore Backend Branding Bundle

This bundle allows you to configure the branding of thr Pimcore admin backend.

## Installation

1. **Require the bundle**
Expand All @@ -16,38 +18,36 @@
Neusta\Pimcore\BackendBrandingBundle\NeustaPimcoreBackendBrandingBundle::class => ['all' => true],
```

## Usage

This bundle allows you to configure the backend branding per environment.
The current environment is determined through Symfony's [`kernel.runtime_environment`](https://symfony.com/doc/6.4/reference/configuration/kernel.html#kernel-runtime-environment) parameter,
which can be set via the `APP_RUNTIME_ENV` environment variable.
If not set, it falls back to the [`kernel.environment`](https://symfony.com/doc/6.4/reference/configuration/kernel.html#kernel-environment),
which is set via the `APP_ENV` environment variable.
## Configuration

```yaml
neusta_pimcore_backend_branding:
environments:
dev:
title: ACME
sidebarColor: '#fcc243'
staging:
sidebarColor: '#005ea1'
prod:
title:
login: Welcome to ACME!
backend: '{hostname} :: ACME'
favIcon: <url-of-your-fav-icon>
bezelColor: '#00a13a'
signet: # or just: <url-of-your-logo>
url: <url-of-your-logo>
size: 70%
position: center
color: '#000'
tabBarIcon:
url: <url-of-your-logo>
size: 40px
favIcon: <url-of-your-fav-icon>
signet: # or just: <url-of-your-logo>
url: <url-of-your-logo>
size: 70%
position: center
color: '#000'
tabBarIcon:
url: <url-of-your-logo>
size: 40px
when@dev:
neusta_pimcore_backend_branding:
title: ACME Development
sidebarColor: '#fcc243'
when@test:
neusta_pimcore_backend_branding:
title: ACME Testing
sidebarColor: '#005ea1'
when@prod:
neusta_pimcore_backend_branding:
title:
login: Welcome to ACME!
backend: '{hostname} :: ACME'
bezelColor: '#00a13a'
```

## Contribution
Expand Down
8 changes: 2 additions & 6 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@
use Neusta\Pimcore\BackendBrandingBundle\EventListener\BackendAssetsListener;
use Neusta\Pimcore\BackendBrandingBundle\EventListener\BackendResponseListener;
use Neusta\Pimcore\BackendBrandingBundle\Settings;
use Neusta\Pimcore\BackendBrandingBundle\SettingsFactory;

return static function (ContainerConfigurator $container) {
$container->services()
->set(Settings::class)
->factory([service(SettingsFactory::class), 'create'])
->args(['%kernel.runtime_environment%'])
->set(SettingsFactory::class)
->arg('$config', param('neusta_pimcore_backend_branding.environments'))
->arg('$denormalizer', service('serializer'))
->factory([service('serializer'), 'denormalize'])
->args([param('neusta_pimcore_backend_branding.config'), Settings::class])
->set(BackendAssetsListener::class)
->autoconfigure()
->arg('$urlGenerator', service('router'))
Expand Down
77 changes: 34 additions & 43 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,41 @@ public function getConfigTreeBuilder(): TreeBuilder
$rootNode = $treeBuilder->getRootNode();

$rootNode
->fixXmlConfig('environment')
->children()
->arrayNode('environments')
->normalizeKeys(false)
->useAttributeAsKey('name')
->arrayPrototype()
->children()
->arrayNode('title')
->beforeNormalization()
->ifString()
->then(fn (string $v) => ['login' => $v, 'backend' => $v])
->end()
->children()
->scalarNode('login')->defaultNull()->end()
->scalarNode('backend')->defaultNull()->end()
->end()
->end()
->scalarNode('favIcon')->end()
->scalarNode('bezelColor')->end()
->scalarNode('sidebarColor')->end()
->arrayNode('signet')
->beforeNormalization()
->ifString()
->then(fn (string $v) => ['url' => $v, 'size' => '70%', 'position' => 'center'])
->end()
->children()
->scalarNode('url')->isRequired()->cannotBeEmpty()->end()
->scalarNode('size')->defaultValue('70%')->end()
->scalarNode('position')->defaultValue('center')->end()
->scalarNode('color')->defaultNull()->end()
->end()
->end()
->arrayNode('tabBarIcon')
->beforeNormalization()
->ifString()
->then(fn (string $v) => ['url' => $v])
->end()
->children()
->scalarNode('url')->isRequired()->cannotBeEmpty()->end()
->scalarNode('size')->defaultNull()->end()
->scalarNode('position')->defaultNull()->end()
->end()
->end()
->end()
->arrayNode('title')
->beforeNormalization()
->ifString()
->then(fn (string $v) => ['login' => $v, 'backend' => $v])
->end()
->children()
->scalarNode('login')->defaultNull()->end()
->scalarNode('backend')->defaultNull()->end()
->end()
->end()
->scalarNode('favIcon')->end()
->scalarNode('bezelColor')->end()
->scalarNode('sidebarColor')->end()
->arrayNode('signet')
->beforeNormalization()
->ifString()
->then(fn (string $v) => ['url' => $v, 'size' => '70%', 'position' => 'center'])
->end()
->children()
->scalarNode('url')->isRequired()->cannotBeEmpty()->end()
->scalarNode('size')->defaultValue('70%')->end()
->scalarNode('position')->defaultValue('center')->end()
->scalarNode('color')->defaultNull()->end()
->end()
->end()
->arrayNode('tabBarIcon')
->beforeNormalization()
->ifString()
->then(fn (string $v) => ['url' => $v])
->end()
->children()
->scalarNode('url')->isRequired()->cannotBeEmpty()->end()
->scalarNode('size')->defaultNull()->end()
->scalarNode('position')->defaultNull()->end()
->end()
->end()
->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected function loadInternal(array $mergedConfig, ContainerBuilder $container
$loader = new PhpFileLoader($container, new FileLocator(\dirname(__DIR__, 2) . '/config'));
$loader->load('services.php');

$container->setParameter('neusta_pimcore_backend_branding.environments', $mergedConfig['environments']);
$container->setParameter('neusta_pimcore_backend_branding.config', $mergedConfig);

$container->registerAttributeForAutoconfiguration(
AsCssProvider::class,
Expand Down
20 changes: 0 additions & 20 deletions src/SettingsFactory.php

This file was deleted.

0 comments on commit fa7e3d7

Please sign in to comment.