KnpLabs/KnpMenuBundle — pull request #243 by kbond (2014-11-26 20:53:00+00:00)
Title: [RFC] Define menus in config, use the ExpressionLanguage for labels and show/hide logic

This PR allow you to define menus in the bundle config:

```yaml
knp_menu:
menus:
my_menu:
children:
login:
route: fos_user_security_login
logout:
route: fos_user_security_logout
```

The menu can be rendered in your templates with `knp_menu_render('my_menu')`

Additionally, you can use the expression language to dynamically change the label or show/hide items:

```yaml
knp_menu:
menus:
my_menu:
children:
login:
route: fos_user_security_login
hide_if: "is_granted('ROLE_USER')"
logout:
expression: "'Logout '~user"
route: fos_user_security_logout
show_if: "is_granted('ROLE_USER')"
```

Variables available in expressions: `user`, `security`, `request`

Functional available in expressions: `is_granted`

You can also use expressions in your `translation_parameters`:

```yaml
knp_menu:
menus:
my_menu:
children:
login:
route: fos_user_security_login
hide_if: "is_granted('ROLE_USER')"
logout:
route: fos_user_security_logout
show_if: "is_granted('ROLE_USER')"
extras:
translation_params_expression:
"%%user%%": user
```

TODO:

- Docs
- Tests
- Optimize expressions during container compilation. I am not an expert on the ExpressionLanguage component. Maybe someone else can help with this? I would like to not have the `expression` and `extra.translation_params_expression` options and just do `label: @=expression` but symfony throws and error when using `@=` in parameters...

If this is something you would want in the bundle, I will write the tests and documentation.