Code Monkey home page Code Monkey logo

configknpmenubundle's Introduction

ConfigKnpMenuBundle

Build Status

Introduction

This bundle provides a way to configure your knp menus in your bundles yml configuration.

For more information on knp menu, read :

This bundle was inspired by the OroNavigationBundle in oro crm.

Installation

You can use composer for installation.

Add the repository to the composer.json file of your project and run the update or install command.

{
    "require": {
        "jbouzekri/config-knp-menu-bundle": "3.0.0"
    }
}

Then enable it in your AppKernel.php with the KnpMenuBundle :

$bundles = array(
    ...
    new Knp\Bundle\MenuBundle\KnpMenuBundle(),
    new Jb\Bundle\ConfigKnpMenuBundle\JbConfigKnpMenuBundle(),
);

Documentation

In order to use this bundle, you must define your menu configuration in a navigation.yml file in your bundle.

Example :

my_mega_menu:
    tree:
        first_level_item:
            label: My first label
            children:
                second_level_item:
                    label: My second level

It will configure a provider for knp menu factory. You can then use your my_mega_menu in twig as a classic knp menu :

{{ knp_menu_render('my_mega_menu') }}

Configuration

This is the available configuration definition for an item.

my_mega_menu:
    childrenAttributes: An array of attributes passed to the root ul tag
    tree:
        first_level_item:
            uri: "An uri. Use it if you do not define route parameter"
            route: "A sf2 route without @"
            routeParameters: "an array of parameters to pass to the route"
            label: "My first label"
            order: An integer to sort the item in his level.
            attributes: An array of attributes passed to the knp item
            linkAttributes: An array of attributes passed to the a tag
            childrenAttributes: An array of attributes passed to the chidlren block
            labelAttributes: An array of attributes passed to the label tag
            display: boolean to hide the item
            displayChildren: boolean to hide the children
            roles: array of item (string roles) passed to isGranted securityContext method to check if user has rights in menu items
            children: # An array of subitems
                second_level_item:
                    label: My second level

This configuration matches the methods available in the Knp Menu Item class

Menu security

Security context is injected in menu item provider.

For root menu item, display or hide it in your twig template. For children items, if you didn't add the roles key, they will be displayed. Else it will passed the array of key to the isGranted method and check if you have rights on the the item.

Issues

  • tree sub configuration property : In the navigation.yml file, you must defined a tree key below your menu name. It provides another level to keep the first level item key after configuration parsing. If someone know how to remove it, let me know.

configknpmenubundle's People

Contributors

firestorm23 avatar jbouzekri avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.