eschmar/menu-bundle

Simple Object oriented menus for Symfony.

Installs: 157

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:symfony-bundle

v1.0.0 2019-02-20 21:39 UTC

This package is auto-updated.

Last update: 2024-04-11 19:12:01 UTC


README

Simple Object oriented menus for Symfony with role permissions.

Installation

Composer (Packagist):

composer require eschmar/menu-bundle ^1.0.0 # Symfony 4

See eschmar/menu-bundle ^0.2.0 for Symfony 3.

Usage

Create a new <Name>Menu class extending the AbstractMenu for each of your menus in your App\Menu namespace:

namespace App\Menu;

use Eschmar\MenuBundle\Menu\AbstractMenu;

class TestMenu extends AbstractMenu
{
    public function generateMenu()
    {
        // create root node
        $this->root = $this->newNode('Navigation');

        // append a new node for each navigation element
        $this->root->node('Link 1');
        $this->root->node('Link 2');
        $this->root->node('Link 3');

        // multi-dimensional
        $this->root['Link 2']->node('Sublink 1');
        $this->root['Link 2']['Sublink 1']->node('Subsublink 1');

        // generate route
        $this->root['Link 3']->node('Sublink 3', null, 'acme_hello_homepage');

        // role permissions
        $this->root['Link 3']->node('Sublink 2', null, null, 'ROLE_ADMIN', array());
    }

} // END class TestMenu

Render the menu directly in twig:

{{ menu('TestMenu') }}

{# override template #}
{{ menu('TestMenu', 'test/mobile.html.twig') }}
```

# License
MIT License.