Skip to content

Commit

Permalink
#68 Ajout d'icônes dynamiques pour les liens des menus.
Browse files Browse the repository at this point in the history
  • Loading branch information
noelma committed Jul 23, 2019
1 parent 04e8392 commit d6689d5
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 62 deletions.
9 changes: 2 additions & 7 deletions core/modules/Config/Installer.php
Expand Up @@ -30,15 +30,10 @@ public function hookInstallMenu(ContainerInterface $ci)
if ($ci->module()->has('Menu')) {
$ci->query()
->insertInto('menu_link', [
'key', 'title_link', 'link', 'menu', 'weight', 'parent'
'key', 'icon', 'title_link', 'link', 'menu', 'weight', 'parent'
])
->values([
'config.index',
'<i class="fa fa-cog" aria-hidden="true"></i> Configuration',
'admin/config',
'menu-admin',
6,
-1
'config.index', 'fa fa-cog', 'Configuration', 'admin/config', 'menu-admin', 6, -1
])
->execute();
}
Expand Down
31 changes: 29 additions & 2 deletions core/modules/Menu/Controller/Link.php
Expand Up @@ -22,7 +22,7 @@ public function __construct()

public function create($nameMenu)
{
$content = [ 'title_link' => '', 'link' => '', 'target_link' => '_self' ];
$content = [ 'title_link' => '', 'icon' => '', 'link' => '', 'target_link' => '_self' ];

$this->container->callHook('menu.link.create.form.data', [ &$content ]);

Expand Down Expand Up @@ -56,6 +56,17 @@ public function create($nameMenu)
'value' => $content[ 'link' ],
]);
}, [ 'class' => 'form-group' ])
->group('menu-link-icon-group', 'div', function ($form) use ($content) {
$form->label('menu-link-icon-label', 'Icon',[
'data-tooltip' => 'Les icônes sont créées à partir des class CSS de FontAwesome'
])
->text('icon', 'icon', [
'class' => 'form-control',
'maxlength' => 255,
'placeholder' => 'CSS fontAwesome : fa fa-bars, fa fa-home...',
'value' => $content[ 'icon' ],
]);
}, [ 'class' => 'form-group' ])
->group('menu-link-target-group', 'div', function ($form) use ($content) {
$form->label('menu-link-target-label', 'Cîble')
->select('target_link', 'target_link', self::$optionTarget, [
Expand Down Expand Up @@ -99,6 +110,7 @@ public function store($nameMenu, $req)
->setRules([
'title_link' => 'required|string|max:255|striptags',
'link' => 'required',
'icon' => '!required|string|max:255|striptags',
'target_link' => 'required|inArray:_blank,_self,_parent,_top',
'token_link_create' => 'required|token'
])
Expand All @@ -114,6 +126,7 @@ public function store($nameMenu, $req)
if ($validator->isValid() && $isUrlOrRoute) {
$data = [
'title_link' => $validator->getInput('title_link'),
'icon' => $validator->getInput('icon'),
'link' => $validator->getInput('link'),
'target_link' => $validator->getInput('target_link'),
'menu' => $nameMenu,
Expand Down Expand Up @@ -177,6 +190,7 @@ public function edit($name, $id, $req)
$form->label('menu-link-title-label', 'Titre du lien')
->text('title_link', 'title_link', [
'class' => 'form-control',
'maxlength' => 255,
'placeholder' => 'Exemple: Ma page 1',
'required' => 1,
'value' => $query[ 'title_link' ]
Expand All @@ -191,6 +205,17 @@ public function edit($name, $id, $req)
'value' => $query[ 'link' ]
]);
}, [ 'class' => 'form-group' ])
->group('menu-link-icon-group', 'div', function ($form) use ($query) {
$form->label('menu-link-icon-label', 'Icon',[
'data-tooltip' => 'Les icônes sont créées à partir des class CSS de FontAwesome'
])
->text('icon', 'icon', [
'class' => 'form-control',
'maxlength' => 255,
'placeholder' => 'CSS fontAwesome : fa fa-bars, fa fa-home...',
'value' => $query[ 'icon' ],
]);
}, [ 'class' => 'form-group' ])
->group('menu-link-target-group', 'div', function ($form) use ($query) {
$form->label('menu-link-target-label', 'Cîble')
->select('target_link', 'target_link', self::$optionTarget, [
Expand Down Expand Up @@ -236,7 +261,8 @@ public function update($nameMenu, $id, $req)

$validator = (new Validator())
->setRules([
'title_link' => 'required|string|max:255|striptags',
'title_link' => 'required|string|max:255|htmlsc',
'icon' => '!required|string|max:255|htmlsc',
'link' => 'required',
'target_link' => 'required|inArray:_blank,_self,_parent,_top',
'token_link_edit' => 'required|token'
Expand All @@ -253,6 +279,7 @@ public function update($nameMenu, $id, $req)
if ($validator->isValid() && $isUrlOrRoute) {
$data = [
'title_link' => $validator->getInput('title_link'),
'icon' => $validator->getInput('icon'),
'link' => $validator->getInput('link'),
'target_link' => $validator->getInput('target_link')
];
Expand Down
7 changes: 4 additions & 3 deletions core/modules/Menu/Installer.php
Expand Up @@ -23,6 +23,7 @@ public function install(ContainerInterface $ci)
->createTableIfNotExists('menu_link', function (TableBuilder $table) {
$table->increments('id')
->string('key')->nullable()
->string('icon')->nullable()
->string('link')
->string('title_link')
->string('target_link')->valueDefault('_self')
Expand All @@ -44,13 +45,13 @@ public function seeders(ContainerInterface $ci)

$ci->query()
->insertInto('menu_link', [
'key', 'title_link', 'link', 'menu', 'weight', 'parent'
'key', 'icon', 'title_link', 'link', 'menu', 'weight', 'parent'
])
->values([
null, 'Site de Soosyze', 'https:\\soosyze.com', 'menu-main', 10, -1
null, null, 'Site de Soosyze', 'https:\\soosyze.com', 'menu-main', 10, -1
])
->values([
'menu.show', '<i class="fa fa-bars" aria-hidden="true"></i> Menu', 'menu/menu-main', 'menu-admin', 3, -1
'menu.show', 'fa fa-bars', 'Menu', 'menu/menu-main', 'menu-admin', 3, -1
])
->execute();
}
Expand Down
2 changes: 1 addition & 1 deletion core/modules/Menu/Views/menu-show.php
Expand Up @@ -7,7 +7,7 @@
<div class="link-title">
<i class="fa fa-arrows-alt" aria-hidden="true"></i>
<a href="<?php echo $link[ 'link' ]; ?>" target="<?php echo $link[ 'target_link' ]; ?>" <?php if ($link[ 'target_link' ] === '_blank'): ?> rel="noopener noreferrer" <?php endif; ?>>
<?php echo $link[ 'title_link' ]; ?>
<?php echo !empty($link['icon']) ? "<i class='{$link['icon']}' aria-hidden='true'></i> {$link[ 'title_link' ]}" : $link[ 'title_link' ]; ?>
</a>
</div>
<div class="link-actions">
Expand Down
6 changes: 3 additions & 3 deletions core/modules/Menu/Views/menu.php
Expand Up @@ -6,14 +6,14 @@
<?php if (!empty($link[ 'submenu' ])): ?>

<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<?php echo $link[ 'title_link' ]; ?> <span class="caret"></span>
<?php echo !empty($link['icon']) ? "<i class='{$link['icon']}' aria-hidden='true'></i> {$link[ 'title_link' ]}" : $link[ 'title_link' ]; ?> <span class="caret"></span>

</a>
<?php else: ?>

<a href="<?php echo $link[ 'link' ]; ?>" target="<?php echo $link[ 'target_link' ]; ?>" <?php if ($link[ 'target_link' ] === '_blank'): ?> rel="noopener noreferrer" <?php endif; ?>>
<?php echo $link[ 'title_link' ]; ?>
<?php echo !empty($link['icon']) ? "<i class='{$link['icon']}' aria-hidden='true'></i> {$link[ 'title_link' ]}" : $link[ 'title_link' ]; ?>

</a>
<?php endif; ?>
<?php if (!empty($link[ 'submenu' ])): ?>
Expand Down
22 changes: 7 additions & 15 deletions core/modules/Node/Installer.php
Expand Up @@ -193,27 +193,19 @@ public function hookInstallMenu(ContainerInterface $ci)
if ($ci->module()->has('Menu')) {
$ci->query()
->insertInto('menu_link', [
'key', 'title_link', 'link', 'menu', 'weight', 'parent'
'key', 'icon', 'title_link', 'link', 'menu', 'weight', 'parent'
])
->values([
'node.index',
'<i class="fa fa-file" aria-hidden="true"></i> Contenu',
'admin/node',
'menu-admin',
2,
-1
'node.index', 'fa fa-file', 'Contenu', 'admin/node', 'menu-admin', 2, -1
])
->values([
'node.show', 'Page', 'node/3', 'menu-main', 2, -1
'node.show', null, 'Page', 'node/3', 'menu-main', 2, -1
])
->values([ 'node.show', 'Accueil', '/', 'menu-main', 1, -1 ])
->values([
'node.show',
'<i class="fa fa-home" aria-hidden="true"></i> Accueil',
'/',
'menu-admin',
1,
-1
'node.show', null, 'Accueil', '/', 'menu-main', 1, -1
])
->values([
'node.show', 'fa fa-home', 'Accueil', '/', 'menu-admin', 1, -1
])
->execute();

Expand Down
5 changes: 3 additions & 2 deletions core/modules/Node/Services/HookMenu.php
Expand Up @@ -113,8 +113,9 @@ public function hookStoreValid($validator)

if ($nodeLast) {
$id = $nodeLast[ 'id' ];
$this->query->insertInto('menu_link', [ 'key', 'title_link', 'link',
'menu', 'weight', 'parent', 'active' ])
$this->query->insertInto('menu_link', [
'key', 'title_link', 'link', 'menu', 'weight', 'parent', 'active'
])
->values([
'node.show',
$validator->getInput('title_link'),
Expand Down
9 changes: 2 additions & 7 deletions core/modules/System/Installer.php
Expand Up @@ -70,15 +70,10 @@ public function hookInstallMenu(ContainerInterface $ci)
if ($ci->module()->has('Menu')) {
$ci->query()
->insertInto('menu_link', [
'key', 'title_link', 'link', 'menu', 'weight', 'parent'
'key', 'icon', 'title_link', 'link', 'menu', 'weight', 'parent'
])
->values([
'system.module.edit',
'<i class="fa fa-th-large" aria-hidden="true"></i> Modules',
'admin/modules',
'menu-admin',
5,
-1
'system.module.edit', 'fa fa-th-large', 'Modules', 'admin/modules', 'menu-admin', 5, -1
])
->execute();
}
Expand Down
21 changes: 5 additions & 16 deletions core/modules/User/Installer.php
Expand Up @@ -93,30 +93,19 @@ public function hookInstallMenu(ContainerInterface $ci)
if ($ci->module()->has('Menu')) {
$ci->query()
->insertInto('menu_link', [
'key', 'title_link', 'link', 'menu', 'weight', 'parent'
'key', 'icon', 'title_link', 'link', 'menu', 'weight', 'parent'
])
->values([
'user.management.admin',
'<i class="fa fa-user" aria-hidden="true"></i> Utilisateur',
'admin/user',
'menu-admin',
4,
-1
'user.management.admin', 'fa fa-user', 'Utilisateur', 'admin/user', 'menu-admin', 4, -1
])
->values([
'user.account', 'Mon compte', 'user/account', 'menu-user', 1,
-1
'user.account', null, 'Mon compte', 'user/account', 'menu-user', 1, -1
])
->values([
'user.login', 'Connexion', 'user/login', 'menu-user', 2, -1
'user.login', null, 'Connexion', 'user/login', 'menu-user', 2, -1
])
->values([
'user.logout',
'<i class="fa fa-power-off" aria-hidden="true"></i> Déconnexion',
'user/logout',
'menu-user',
3,
-1
'user.logout', 'fa fa-power-off', 'Déconnexion', 'user/logout', 'menu-user', 3, -1
])
->execute();
}
Expand Down
4 changes: 2 additions & 2 deletions core/themes/Admin/menu-user.php
Expand Up @@ -6,13 +6,13 @@
<?php if (!empty($link[ 'submenu' ])): ?>

<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<?php echo $link[ 'title_link' ]; ?> <span class="caret"></span>
<?php echo !empty($link['icon']) ? "<i class='{$link['icon']}' aria-hidden='true'></i> " : ''; ?><?php echo $link[ 'title_link' ]; ?> <span class="caret"></span>

</a>
<?php else: ?>

<a href="<?php echo $link[ 'link' ]; ?>" target="<?php echo $link[ 'target_link' ]; ?>" <?php if ($link[ 'target_link' ] === '_blank'): ?> rel="noopener noreferrer" <?php endif; ?>>
<?php echo $link[ 'title_link' ]; ?>
<?php echo !empty($link['icon']) ? "<i class='{$link['icon']}' aria-hidden='true'></i> " : ''; ?><?php echo $link[ 'title_link' ]; ?>

</a>
<?php endif; ?>
Expand Down
4 changes: 2 additions & 2 deletions core/themes/Admin/menu.php
Expand Up @@ -6,13 +6,13 @@
<?php if (!empty($link[ 'submenu' ])): ?>

<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<?php echo $link[ 'title_link' ]; ?> <span class="caret"></span>
<?php echo !empty($link['icon']) ? "<i class='{$link['icon']}' aria-hidden='true'></i> " : ''; ?><?php echo $link[ 'title_link' ]; ?> <span class="caret"></span>

</a>
<?php else: ?>

<a href="<?php echo $link[ 'link' ]; ?>" target="<?php echo $link[ 'target_link' ]; ?>" <?php if ($link[ 'target_link' ] === '_blank'): ?> rel="noopener noreferrer" <?php endif; ?>>
<?php echo $link[ 'title_link' ]; ?>
<?php echo !empty($link['icon']) ? "<i class='{$link['icon']}' aria-hidden='true'></i> " : ''; ?><?php echo $link[ 'title_link' ]; ?>

</a>
<?php endif; ?>
Expand Down
4 changes: 3 additions & 1 deletion core/themes/Bootstrap3/menu-user.php
Expand Up @@ -4,7 +4,9 @@
<?php foreach ($menu as $link): ?>

<li>
<a href="<?php echo $link[ 'link' ]; ?>" class="btn btn-action"><?php echo $link[ 'title_link' ]; ?></a>
<a href="<?php echo $link[ 'link' ]; ?>" class="btn btn-action">
<?php echo !empty($link['icon']) ? "<i class='{$link['icon']}' aria-hidden='true'></i> {$link[ 'title_link' ]}" : $link[ 'title_link' ]; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion core/themes/QuietBlue/menu.php
Expand Up @@ -4,7 +4,7 @@

<li class="<?php echo $link[ 'link_active' ]; ?> <?php if (!empty($link[ 'submenu' ])): echo 'parent'; endif; ?>">
<a href="<?php echo $link[ 'link' ]; ?>" target="<?php echo $link[ 'target_link' ]; ?>" <?php if ($link[ 'target_link' ] === '_blank'): ?> rel="noopener noreferrer" <?php endif; ?>>
<?php echo $link[ 'title_link' ]; ?>
<?php echo !empty($link['icon']) ? "<i class='{$link['icon']}' aria-hidden='true'></i> " : ''; ?><?php echo $link[ 'title_link' ]; ?>

</a>
<?php if (!empty($link[ 'submenu' ])): ?>
Expand Down

0 comments on commit d6689d5

Please sign in to comment.