Skip to content

Commit a911cce

Browse files
author
Thomas Jarrand
committed
Initial commit
0 parents  commit a911cce

17 files changed

Lines changed: 656 additions & 0 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor/
2+
composer.lock
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Elao\Bundle\AdminThemeBundle\DependencyInjection;
4+
5+
use Symfony\Component\Config\FileLocator;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
use Symfony\Component\DependencyInjection\Extension\Extension;
8+
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
9+
use Symfony\Component\HttpFoundation\RequestStack;
10+
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
11+
12+
class ElaoAdminThemeExtension extends Extension
13+
{
14+
public function load(array $configs, ContainerBuilder $container)
15+
{
16+
$loader = new PhpFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
17+
$loader->load('services.php');
18+
}
19+
}

ElaoAdminThemeBundle.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Elao\Bundle\AdminThemeBundle;
4+
5+
use Symfony\Component\HttpKernel\Bundle\Bundle;
6+
7+
class ElaoAdminThemeBundle extends Bundle
8+
{
9+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 élao
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
###########
2+
# Install #
3+
###########
4+
5+
install:
6+
composer install
7+
8+
########
9+
# Lint #
10+
########
11+
12+
lint: lint-twig
13+
14+
lint-twig:
15+
php bin/lint.twig.php Resources/views

Menu/Builder.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
namespace Elao\Bundle\AdminThemeBundle\Menu;
4+
5+
use Symfony\Component\HttpFoundation\RequestStack;
6+
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
7+
8+
class Builder
9+
{
10+
private RequestStack $requestStack;
11+
private UrlGeneratorInterface $urlGenerator;
12+
13+
public function __construct(RequestStack $requestStack, UrlGeneratorInterface $urlGenerator)
14+
{
15+
$this->requestStack = $requestStack;
16+
$this->urlGenerator = $urlGenerator;
17+
}
18+
19+
public function getMenuPath(array $item): string
20+
{
21+
if (isset($item['url'])) {
22+
return $item['url'];
23+
}
24+
25+
if (isset($item['route'])) {
26+
return $this->urlGenerator->generate($item['route'], isset($item['parameters']) ? $item['parameters'] : []);
27+
}
28+
29+
return '#';
30+
}
31+
32+
/**
33+
* Is the given menu item active?
34+
*/
35+
public function isActive(array $item): bool
36+
{
37+
if (isset($item['active'])) {
38+
return (bool) $item['active'];
39+
}
40+
41+
return (isset($item['root']) && $this->isCurrentRoot($item['root']))
42+
|| (isset($item['branch']) && $this->isCurrentBranch($item['branch']))
43+
|| (isset($item['route']) && $this->isCurrentRoute($item['route']));
44+
}
45+
46+
public function isCurrentRoot(string $root): bool
47+
{
48+
return $this->getCurrentAttribute('_root') === $root;
49+
}
50+
51+
public function isCurrentBranch(string $branch): bool
52+
{
53+
return $this->getCurrentAttribute('_branch') === $branch;
54+
}
55+
56+
public function isCurrentRoute(string $route): bool
57+
{
58+
return $this->getCurrentAttribute('_route') === $route;
59+
}
60+
61+
public function addParametersToCurrentUrl(array $parameters, int $referenceType = null): string
62+
{
63+
return $this->urlGenerator->generate(
64+
$this->getCurrentAttribute('_route'),
65+
array_merge(
66+
$this->getCurrentAttribute('_route_params'),
67+
$this->getCurrentQuery(),
68+
$parameters
69+
),
70+
$referenceType
71+
);
72+
}
73+
74+
/**
75+
* Get attribute from current request
76+
*
77+
* @return string|array
78+
*/
79+
private function getCurrentAttribute(string $name)
80+
{
81+
return $this->requestStack->getCurrentRequest()->attributes->get($name);
82+
}
83+
84+
private function getCurrentQuery(): array
85+
{
86+
return $this->requestStack->getCurrentRequest()->query->all();
87+
}
88+
}

README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# elao-admin theme bundle
2+
3+
> Twig template set for [elao-admin](https://github.com/Elao/elao-admin)
4+
5+
## Installation
6+
7+
composer config repositories.elao/admin-theme-bundle vcs https://github.com/Elao/ElaoAdminThemeBundle.git
8+
composer require elao/admin-theme-bundle
9+
10+
## Usage
11+
12+
Yourbase template should extends elao admin theme base:
13+
14+
```twig
15+
{# template/base.html.twig #}
16+
{% extends '@ElaoAdminTheme/base.html.twig' %}
17+
18+
{# HEAD #}
19+
20+
{% block stylesheets %}
21+
{{ encore_entry_link_tags('style') }}
22+
{% endblock %}
23+
24+
{% block javascripts %}
25+
{{ encore_entry_script_tags('app') }}
26+
{% endblock %}
27+
28+
{% block title 'Demo Admin' %}
29+
30+
{% block logo 'Demo' %}
31+
32+
{# MENUS #}
33+
34+
{% set menu_user = [
35+
{ route: 'profile', label: 'Profil' },
36+
{ url: '/logout', label: 'Déconnexion' },
37+
] %}
38+
39+
{% set menu_primary = [
40+
{ route: 'user_list', label: 'Utilisateurs', root: 'user', icon: 'user' },
41+
{ route: 'bill_list', label: 'Factures', icon: 'bill' },
42+
] %}
43+
44+
{# MOBILE MENU #}
45+
46+
{% set menu_mobile = [
47+
{ label: 'Utilisateurs', root: 'user', children: [
48+
{ label: 'Liste des utilisateurs', branch: 'user_list', children: [
49+
{ route: 'user_list', label: 'Tous les utilisateurs' },
50+
{ route: 'user_list_archived', label: 'Utilisateurs archivés' },
51+
] },
52+
{ route: 'user_create', label: 'Nouvel utilisateur' },
53+
] },
54+
{ label: 'Factures', route: 'bill_list' },
55+
{ label: 'Profil', route: 'profile', },
56+
{ label: 'Déconnexion', url: '/logout', },
57+
] %}
58+
59+
```
60+
61+
### Page
62+
63+
```twig
64+
{# templte/user/base.html.twig #}
65+
{% extends 'base.html.twig' %}
66+
67+
{% set menu_secondary = [
68+
{ route: 'user_list', label: 'Liste des utilisateurs', branch: 'user_list' },
69+
{ route: 'user_create', label: 'Nouvel utilisateur', icon: 'plus' },
70+
]%}
71+
```
72+
73+
```twig
74+
{# templte/user/list.html.twig #}
75+
{% extends 'user/base.html.twig' %}
76+
77+
{% block title %}Utilisateurs{% endblock %}
78+
79+
{% set menu_tertiary = [
80+
{ route: 'user_list', label: 'Tous les utilisateurs' },
81+
{ route: 'user_list_archived', label: 'Utilisateurs archivés' },
82+
]%}
83+
84+
{% block content %}
85+
{# ... #}
86+
{% endblock %}
87+
```
88+
89+
### Drop
90+
91+
```twig
92+
{% embed "@ElaoAdminTheme/components/drop.html.twig" only %}
93+
{% block drop_direction 'left' %}
94+
{% block tooltip_direction 'top' %}
95+
{% block tooltip_label 'Choisir une action' %}
96+
{% block drop_menu %}
97+
{% set menu = [
98+
{ url: '#show', label: 'Consulter' },
99+
{ url: '#edit', label: 'Éditer' },
100+
{ url: '#delete', label: 'Supprimer' },
101+
] %}
102+
{{ parent() }}
103+
{% endblock %}
104+
{% endembed %}
105+
```

Resources/config/services.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
4+
5+
use Elao\Bundle\AdminThemeBundle\Twig\Extensions\MenuExtension;
6+
use Elao\Bundle\AdminThemeBundle\Menu\Builder;
7+
use Symfony\Component\HttpFoundation\RequestStack;
8+
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
9+
10+
return static function (ContainerConfigurator $container): void {
11+
$container->services()
12+
13+
->set(MenuExtension::class)
14+
->args([
15+
'$builder' => service(Builder::class),
16+
])
17+
->tag('twig.extension')
18+
19+
->set(Builder::class)
20+
->args([
21+
'$requestStack' => service(RequestStack::class),
22+
'$urlGenerator' => service(UrlGeneratorInterface::class),
23+
])
24+
->tag('twig.runtime')
25+
;
26+
};

0 commit comments

Comments
 (0)