Commit 0af28575 authored by dj3c1t's avatar dj3c1t

header menus

parent e1c5f630
Pipeline #44 skipped
......@@ -8,6 +8,7 @@ use Dj3c1t\AppBundle\Entity\DefaultConfiguration;
class HeaderController extends Controller {
public function displayAction() {
$header_menus = $this->get("dj3c1t_app.header_menus");
$em = $this->getDoctrine()->getManager();
$configurationRepo = $em->getRepository("Dj3c1tAppBundle:Configuration");
if(!($site_title = $configurationRepo->getConfiguration("site_title"))) {
......@@ -17,6 +18,7 @@ class HeaderController extends Controller {
'Dj3c1tAppBundle::header.html.twig',
array(
"site_title" => $site_title,
"menu" => $header_menus->getHeaderMenu(),
)
);
}
......
......@@ -13,6 +13,10 @@ services:
class: Dj3c1t\AppBundle\Service\Menus
arguments: ['@service_container']
dj3c1t_app.header_menus:
class: Dj3c1t\AppBundle\Service\HeaderMenus
arguments: ['@service_container']
gedmo.listener.timestampable:
class: Gedmo\Timestampable\TimestampableListener
tags:
......
......@@ -24,7 +24,7 @@ body {
}
#header {
height: 5em;
min-height: 5em;
}
#header .content{
......
......@@ -48,3 +48,20 @@
</ul>
<h1><a href="{{ path('homepage') }}">{{ site_title }}</a></h1>
<div class="row">
<div class="col-md-12">
{% for item in menu %}
{% if item['parameters'] is defined %}
<a class="btn btn-default" href="{{ path(item['route'], item['parameters']) }}"{% if item['class'] is defined %} class="{{ item['class'] }}"{% endif %}>
{% else %}
<a class="btn btn-default" href="{{ path(item['route']) }}"{% if item['class'] is defined %} class="{{ item['class'] }}"{% endif %}>
{% endif %}
{% if item['glyphicon'] is defined %}
<span class="glyphicon {{ item['glyphicon'] }}" aria-hidden="true"></span>
{% endif %}
<span class="menu-label">{{ item['label'] }}</span>
</a>
{% endfor %}
</div>
</div>
<?php
namespace Dj3c1t\AppBundle\Service;
use Symfony\Component\DependencyInjection\ContainerInterface as Container;
class HeaderMenus {
private $container;
public function __construct(Container $container) {
$this->container = $container;
}
public function getHeaderMenu() {
$em = $this->container->get('doctrine')->getManager();
$configurationRepo = $em->getRepository("Dj3c1tAppBundle:Configuration");
$menu = array();
if($menuJson = $configurationRepo->getConfiguration("header_menu")) {
$menu = json_decode($menuJson, true);
}
return $menu;
}
}
......@@ -17,9 +17,8 @@ class Menus {
}
public function getMenu($route) {
if(isset($this->menu)) {
return $this->menu;
}
$this->menu = array();
$this->menuName = null;
$bundles = $this->container->getParameter('kernel.bundles');
foreach($bundles as $bundleName => $bundleValues) {
$this->loadMenuName($bundleName, $route);
......@@ -28,7 +27,17 @@ class Menus {
}
}
foreach($bundles as $bundleName => $bundleValues) {
$this->loadMenus($bundleName, $route);
$this->loadMenus($bundleName);
}
return $this->menu;
}
public function getMenuByName($menuName) {
$this->menu = array();
$this->menuName = $menuName;
$bundles = $this->container->getParameter('kernel.bundles');
foreach($bundles as $bundleName => $bundleValues) {
$this->loadMenus($bundleName);
}
return $this->menu;
}
......@@ -55,7 +64,7 @@ class Menus {
}
}
public function loadMenus($bundleName, $route) {
public function loadMenus($bundleName) {
if(isset($this->menuName)) {
try {
$kernel = $this->container->get('kernel');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment