baconmanager/menu-bundle

This bundle of symfony2

Installs: 1 110

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 4

Forks: 1

Open Issues: 0

Type:symfony-bundle

v0.1 2016-01-03 19:41 UTC

This package is not auto-updated.

Last update: 2024-12-21 20:35:56 UTC


README

Codacy Badge Latest Stable Version License SensioLabsInsight

Este bundle é responsavel por Customizar a criação de menus do KnpMenuBundle

Instalação

Para instalar o bundle basta rodar o seguinte comando abaixo:

$ composer require baconmanager/menu-bundle

Agora adicione os seguintes bundles no arquivo AppKernel.php:

<?php
// app/AppKernel.php
public function registerBundles()
{
    // ...
    new Knp\Bundle\MenuBundle\KnpMenuBundle(),
    new Bacon\Bundle\MenuBundle\BaconMenuBundle(),
    // ...
}

Configuração

Adicionar as configurações abaixo no arquivo app/config/config.yml

#Menu
knp_menu:
    # use "twig: false" to disable the Twig extension and the TwigRenderer
    twig:
        template: BaconCoreBundle:partial:menu.html.twig
    #  if true, enables the helper for PHP templates
    templating: false
    # the renderer to use, list is also available by default
    default_renderer: twig

Criando um menu

Para criar um novo menu basta criar uma classe no namespace MyBundle/Menu/Builder como no exemplo abaixo:

Para versão symfony =< 2.7

<?php
// src/AppBundle/Menu/Builder.php
namespace AppBundle\Menu;

use Knp\Menu\FactoryInterface;
use Symfony\Component\DependencyInjection\ContainerAware;

class Builder extends ContainerAware
{
    public function addMenu(FactoryInterface $factory, array $options)
    {
        $menu = $factory->createItem('root');

        $translate = $this->container->get('translator');

        // Menu Catalog
        $menu->addChild($translate->trans('Category'))->setAttribute('icon', '<i class="fa fa-book"></i>');
        $menu[$translate->trans('Category')]->addChild($translate->trans('List'),array('route' => 'admin_category'));
        $menu[$translate->trans('Category')]->addChild($translate->trans('New'),array('route' => 'admin_category_new'));

        return $menu;
    }
}

Para versão do symfony >= 2.8

<?php
// src/AppBundle/Menu/Builder.php
namespace AppBundle\Menu;

use Knp\Menu\FactoryInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;

class Builder implements ContainerAwareInterface
{
	use ContainerAwareTrait;
	
    public function addMenu(FactoryInterface $factory, array $options)
    {
        $menu = $factory->createItem('root');

        $translate = $this->container->get('translator');

        // Menu Catalog
        $menu->addChild($translate->trans('Category'))->setAttribute('icon', '<i class="fa fa-book"></i>');
        $menu[$translate->trans('Category')]->addChild($translate->trans('List'),array('route' => 'admin_category'));
        $menu[$translate->trans('Category')]->addChild($translate->trans('New'),array('route' => 'admin_category_new'));

        return $menu;
    }
}

Renderizando o menu no layout(twig):

{{ bacon_menu_full_render() }}