Skip to content

Commit

Permalink
Add hide sidebar configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny van Wijk committed Mar 6, 2024
1 parent 4f28062 commit fe27388
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public function getConfigTreeBuilder()
->scalarNode('service')->defaultNull()->end() // NEXT_MAJOR: switch default value to SymfonyMailerService::class
->scalarNode('from_address')->defaultValue('[email protected]')->end()
->scalarNode('from_name')->defaultValue('Kunstmaan CMS')->end()
->end()
->end()
->end()
->end()
->end()
->scalarNode('dashboard_route')->end()
Expand Down Expand Up @@ -100,14 +100,16 @@ public function getConfigTreeBuilder()
->end()
->end()
->arrayNode('password_restrictions')
->addDefaultsIfNotSet()
->addDefaultsIfNotSet()
->children()
->integerNode('min_digits')->defaultNull()->end()
->integerNode('min_uppercase')->defaultNull()->end()
->integerNode('min_special_characters')->defaultNull()->end()
->integerNode('min_length')->defaultNull()->end()
->integerNode('max_length')->defaultNull()->end()
->end()
->end()
->booleanNode('hide_sidebar')->defaultFalse()->end()
->end();

return $treeBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public function load(array $configs, ContainerBuilder $container)
$container->setParameter('kunstmaan_admin.multi_language', $config['multi_language']);
$container->setParameter('kunstmaan_admin.required_locales', $config['required_locales']);
$container->setParameter('requiredlocales', $config['required_locales']); // Keep old parameter for to keep BC with routing config

$container->setParameter('kunstmaan_admin.hide_sidebar', $config['hide_sidebar']);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Kunstmaan/AdminBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ services:

kunstmaan_admin.sidebar.twig.extension:
class: Kunstmaan\AdminBundle\Twig\SidebarTwigExtension
arguments:
- '%kunstmaan_admin.hide_sidebar%'
tags:
- { name: twig.extension }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@
{% endif %}
{% endif %}

{% if page is defined %}
{% set hideSidebar = hideSidebarInNodeEditAdmin(page) %}
{% else %}
{% set hideSidebar = false %}
{% endif %}
{% set hideSidebar = hideSidebarInNodeEditAdmin(page|default(null)) %}

<!-- Main Content -->
<main role="main" id="app__main" class="container-fluid app__main{% if not hideSidebar and lowestTopChild and navigationChildren | length > 0 %} app__main--has-sidebar{% else %} app__main--no-sidebar{% endif %}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class ConfigurationTest extends TestCase
'from_name' => 'Kunstmaan CMS',
],
],
'hide_sidebar' => false,
];

protected function getConfiguration(): ConfigurationInterface
Expand Down Expand Up @@ -85,6 +86,7 @@ public function testConfigGeneratesAsExpected()
'min_length' => 16,
'max_length' => 26,
],
'hide_sidebar' => true,
];

$expected = array_merge(self::DEFAULT_EXPECTED_CONFIG, [
Expand All @@ -97,6 +99,7 @@ public function testConfigGeneratesAsExpected()
'min_length' => 16,
'max_length' => 26,
],
'hide_sidebar' => true,
]);
$expected['authentication']['enable_new_authentication'] = true;

Expand Down
24 changes: 10 additions & 14 deletions src/Kunstmaan/AdminBundle/Twig/SidebarTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,28 @@

namespace Kunstmaan\AdminBundle\Twig;

use Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder;
use Kunstmaan\NodeBundle\Entity\HideSidebarInNodeEditInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

final class SidebarTwigExtension extends AbstractExtension
{
/**
* Get Twig functions defined in this extension.
*
* @return array
*/
public function getFunctions()
private bool $hideSidebar;

public function __construct(bool $hideSidebar)
{
$this->hideSidebar = $hideSidebar;
}

public function getFunctions(): array
{
return [
new TwigFunction('hideSidebarInNodeEditAdmin', [$this, 'hideSidebarInNodeEditAdmin']),
];
}

/**
* Return the admin menu MenuBuilder.
*
* @return MenuBuilder
*/
public function hideSidebarInNodeEditAdmin($node)
public function hideSidebarInNodeEditAdmin($node): bool
{
return $node instanceof HideSidebarInNodeEditInterface;
return $this->hideSidebar || $node instanceof HideSidebarInNodeEditInterface;
}
}

0 comments on commit fe27388

Please sign in to comment.