2017 © Pedro Peláez
 

symfony-bundle config-knp-menu-bundle

Configure your knp menus with yaml files accross your project bundles

image

igdr/config-knp-menu-bundle

Configure your knp menus with yaml files accross your project bundles

  • Thursday, January 26, 2017
  • by igdr
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2,133 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 5 % Grown

The README.md

ConfigKnpMenuBundle

Introduction

This bundle provides a way to configure your knp menus in your bundles yml configuration., (*1)

For more information on knp menu, read : * The Knp Menu Documentation * The Knp Menu Bundle Documentation, (*2)

Installation

You can use composer for installation., (*3)

Add the repository to the composer.json file of your project and run the update or install command., (*4)

{
    "require": {
        "igdr/config-knp-menu-bundle": "dev-master"
    }
}

Then enable it in your AppKernel.php with the KnpMenuBundle :, (*5)

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

Documentation

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

Example :, (*7)

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

Then you need to define a service., (*8)

my_project.menu.admin:
    class: Knp\Menu\MenuItem
    factory_service: igdr_config_menu.menu.builder
    factory_method: createMenu
    arguments:
      - "@request"
      - "my_mega_menu"
    scope: request
    tags:
        - { name: knp_menu.menu, alias: my_menu }

The second argument must match the name of the menu in navigation.yml. The tag alias will be used in your twig template., (*9)

{{ knp_menu_render('my_menu') }}

Configuration

This is the available configuration definition for an item., (*10)

my_mega_menu:
    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
            display: boolean to hide the item
            displayChildren: boolean to hide the children
            children: # An array of subitems
                second_level_item:
                    label: My second level

This configuration matches the methods available in the Knp Menu Item class, (*11)

The Versions

26/01 2017

dev-master

9999999-dev https://github.com/igdr/ConfigKnpMenuBundle

Configure your knp menus with yaml files accross your project bundles

  Sources   Download

MIT

The Requires

 

ui symfony navigation menu user interface knp