diff --git a/docs/reference/configuration.rst b/docs/reference/configuration.rst index 14ff74a221..0eb6c682fe 100644 --- a/docs/reference/configuration.rst +++ b/docs/reference/configuration.rst @@ -77,6 +77,7 @@ Full Configuration Options sort_admins: false confirm_exit: true js_debug: false + skin: 'skin-black' use_select2: true use_icheck: true use_bootlint: false @@ -181,7 +182,6 @@ Full Configuration Options - bundles/sonatacore/vendor/components-font-awesome/css/font-awesome.min.css - bundles/sonatacore/vendor/ionicons/css/ionicons.min.css - bundles/sonataadmin/vendor/admin-lte/dist/css/AdminLTE.min.css - - bundles/sonataadmin/vendor/admin-lte/dist/css/skins/skin-black.min.css - bundles/sonataadmin/vendor/iCheck/skins/square/blue.css - bundles/sonatacore/vendor/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css - bundles/sonataadmin/vendor/jqueryui/themes/base/jquery-ui.css diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index ce43d8c16a..8264afe1d5 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -134,6 +134,23 @@ public function getConfigTreeBuilder() ->booleanNode('sort_admins')->defaultFalse()->info('Auto order groups and admins by label or id')->end() ->booleanNode('confirm_exit')->defaultTrue()->end() ->booleanNode('js_debug')->defaultFalse()->end() + ->enumNode('skin') + ->defaultValue('skin-black') + ->values([ + 'skin-black', + 'skin-black-light', + 'skin-blue', + 'skin-blue-light', + 'skin-green', + 'skin-green-light', + 'skin-purple', + 'skin-purple-light', + 'skin-red', + 'skin-red-light', + 'skin-yellow', + 'skin-yellow-light', + ]) + ->end() ->booleanNode('use_select2')->defaultTrue()->end() ->booleanNode('use_icheck')->defaultTrue()->end() ->booleanNode('use_bootlint')->defaultFalse()->end() @@ -406,7 +423,6 @@ public function getConfigTreeBuilder() 'bundles/sonatacore/vendor/components-font-awesome/css/font-awesome.min.css', 'bundles/sonatacore/vendor/ionicons/css/ionicons.min.css', 'bundles/sonataadmin/vendor/admin-lte/dist/css/AdminLTE.min.css', - 'bundles/sonataadmin/vendor/admin-lte/dist/css/skins/skin-black.min.css', 'bundles/sonataadmin/vendor/iCheck/skins/square/blue.css', 'bundles/sonatacore/vendor/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css', diff --git a/src/DependencyInjection/SonataAdminExtension.php b/src/DependencyInjection/SonataAdminExtension.php index 9bb814f336..7ac231b09e 100644 --- a/src/DependencyInjection/SonataAdminExtension.php +++ b/src/DependencyInjection/SonataAdminExtension.php @@ -226,6 +226,11 @@ public function getNamespace() private function buildStylesheets(array $config): array { + $config['assets']['stylesheets'][] = sprintf( + 'bundles/sonataadmin/vendor/admin-lte/dist/css/skins/%s.min.css', + $config['options']['skin'] + ); + return $this->mergeArray( $config['assets']['stylesheets'], $config['assets']['extra_stylesheets'], diff --git a/src/Resources/views/standard_layout.html.twig b/src/Resources/views/standard_layout.html.twig index 01b3896d07..66745a6285 100644 --- a/src/Resources/views/standard_layout.html.twig +++ b/src/Resources/views/standard_layout.html.twig @@ -21,6 +21,7 @@ file that was distributed with this source code. {% set _actions = block('actions') is defined ? block('actions')|trim : null %} {% set _navbar_title = block('navbar_title') is defined ? block('navbar_title')|trim : null %} {% set _list_filters_actions = block('list_filters_actions') is defined ? block('list_filters_actions')|trim : null -%} +{% set _skin = sonata_admin.adminPool.getOption('skin') %} {% set _use_select2 = sonata_admin.adminPool.getOption('use_select2') %} {% set _use_icheck = sonata_admin.adminPool.getOption('use_icheck') %} @@ -35,6 +36,7 @@ file that was distributed with this source code. container->getDefinition('sonata.admin.pool')->getArgument(3)['stylesheets']; $this->assertSame( - array_merge($this->defaultConfiguration['assets']['stylesheets'], $extraStylesheets), + array_merge($this->getDefaultStylesheets(), $extraStylesheets), $stylesheets ); } @@ -346,8 +347,81 @@ public function testLegacyTextExtensionConfiguration(): void $this->assertNull($this->container->getDefinition('sonata.string.twig.extension')->getArgument(0)); } + public function testDefaultSkin(): void + { + $this->container->setParameter('kernel.bundles', []); + $this->load(); + + $stylesheets = $this->container->getDefinition('sonata.admin.pool')->getArgument(3)['stylesheets']; + $skin = $this->container->getDefinition('sonata.admin.pool')->getArgument(3)['skin']; + + $this->assertSame($this->getDefaultStylesheets(), $stylesheets); + $this->assertSame('skin-black', $skin); + } + + public function testSetSkin(): void + { + $this->container->setParameter('kernel.bundles', []); + $this->load([ + 'options' => [ + 'skin' => 'skin-blue', + ], + ]); + + $stylesheets = $this->container->getDefinition('sonata.admin.pool')->getArgument(3)['stylesheets']; + $skin = $this->container->getDefinition('sonata.admin.pool')->getArgument(3)['skin']; + + $this->assertSame($this->getDefaultStylesheets('skin-blue'), $stylesheets); + $this->assertSame('skin-blue', $skin); + } + + public function testSetDefaultSkin(): void + { + $this->container->setParameter('kernel.bundles', []); + $this->load([ + 'options' => [ + 'skin' => 'skin-black', + ], + ]); + + $stylesheets = $this->container->getDefinition('sonata.admin.pool')->getArgument(3)['stylesheets']; + $skin = $this->container->getDefinition('sonata.admin.pool')->getArgument(3)['skin']; + + $this->assertSame($this->getDefaultStylesheets(), $stylesheets); + $this->assertSame('skin-black', $skin); + } + + public function testSetInvalidSkin(): void + { + $this->expectException(InvalidConfigurationException::class); + $this->expectExceptionMessage('The value "skin-invalid" is not allowed for path "sonata_admin.options.skin". Permissible values: "skin-black", "skin-black-light", "skin-blue", "skin-blue-light", "skin-green", "skin-green-light", "skin-purple", "skin-purple-light", "skin-red", "skin-red-light", "skin-yellow", "skin-yellow-light"'); + $this->container->setParameter('kernel.bundles', []); + $this->load([ + 'options' => [ + 'skin' => 'skin-invalid', + ], + ]); + } + protected function getContainerExtensions(): array { return [new SonataAdminExtension()]; } + + private function getDefaultStylesheets(?string $skin = 'skin-black'): array + { + $this->load([ + 'options' => [ + 'skin' => $skin, + ], + ]); + + $defaultStylesheets = $this->defaultConfiguration['assets']['stylesheets']; + $defaultStylesheets[] = sprintf( + 'bundles/sonataadmin/vendor/admin-lte/dist/css/skins/%s.min.css', + $this->container->getDefinition('sonata.admin.pool')->getArgument(3)['skin'] + ); + + return $defaultStylesheets; + } }