2017 © Pedro Peláez
 

symfony-bundle menu-bundle

image

dama/menu-bundle

  • Saturday, March 17, 2018
  • by dmaicher
  • Repository
  • 1 Watchers
  • 5 Stars
  • 765 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 7 Versions
  • 84 % Grown

The README.md

dama/menu-bundle

This bundle can be used to build dynamic menus based on granted permissions., (*1)

Step 1: create MenuTreeBuilder

class MainMenuTreeBuilder implements MenuTreeBuilderInterface
{
    public function buildTree(Node $root)
    {
        $root
            ->child('social_media')
                ->setAttr('id', 'main_menu_social_media')
                ->setRequiredPermissions(['ROLE_SOCIAL_MENU'])
                ->child('stream')
                    ->setRoute('social_media_stream')
                    ->setRequiredPermissions(['ROLE_SOCIAL_STREAM'])
                    ->setAdditionalActiveRequestMatcher(static function (Request $request): bool {
                        // additionally will mark node as active if the request path starts with '/foo_bar'
                        return str_starts_with($request->getPathInfo(), '/foo_bar');
                    })
                ->end()
                ->child('update_status')
                    ->setRoute('social_media_update_status')
                    ->setRequiredPermissions(['ROLE_SOCIAL_UPDATE_STATUS'])
                ->end()
                ->ifTrue($someCondition) // only add child node(s) inside if the condition is true
                    ->child('statistics')
                        ->setRoute('social_media_statistics')
                        ->setRequiredPermissions([new Expression("has_role('ROLE_USER')")])
                    ->end()
                ->endIf()
            ->end()
        ;
    }
}

Step 2: add config for your menu

```ỳaml dama_menu: menues: my_main_menu: tree_builder: Your\Namespace\MainMenuTreeBuilder #service ID OR FQCN and no constructor args twig_template: YourNamespace:my_main_menu.html.twig #optional, (*2)



Step 3: render the menu ----------------------- ```twig {{ dama_menu_render('my_main_menu', {'collapse':true, 'nested':false}) }}

The Versions

02/01 2018

v1.3

1.3.0.0 https://github.com/dmaicher/menu-bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Maicher

18/07 2017

v1.2

1.2.0.0 https://github.com/dmaicher/menu-bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Maicher

12/06 2017

v1.1

1.1.0.0 https://github.com/dmaicher/menu-bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Maicher

06/06 2017

v1.0

1.0.0.0 https://github.com/dmaicher/menu-bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Maicher