Git Product home page Git Product logo

knpmenu's Introduction

KnpMenu

The KnpMenu library provides object oriented menus for PHP. It is used by the KnpMenuBundle for Symfony but can now be used stand-alone.

Build Status Latest Stable Version Latest Unstable Version Gitter chat

Installation

KnpMenu uses Composer, please checkout the composer website for more information.

The simple following command will install knp-menu into your project. It also add a new entry in your composer.json and update the composer.lock as well.

composer require knplabs/knp-menu

KnpMenu follows the PSR-4 convention names for its classes, which means you can easily integrate knp-menu classes loading in your own autoloader.

Getting Started

<?php

// Include dependencies installed with composer
require 'vendor/autoload.php';

use Knp\Menu\MenuFactory;
use Knp\Menu\Renderer\ListRenderer;

$factory = new MenuFactory();
$menu = $factory->createItem('My menu');
$menu->addChild('Home', ['uri' => '/']);
$menu->addChild('Comments', ['uri' => '#comments']);
$menu->addChild('Symfony', ['uri' => 'http://symfony.com/']);
$menu->addChild('Happy Awesome Developers');

$renderer = new ListRenderer(new \Knp\Menu\Matcher\Matcher());
echo $renderer->render($menu);

The above menu would render the following HTML:

<ul>
  <li class="first">
    <a href="/">Home</a>
  </li>
  <li class="current">
    <a href="#comments">Comments</a>
  </li>
  <li>
    <a href="http://symfony.com/">Symfony</a>
  </li>
  <li class="last">
    <span>Happy Awesome Developers</span>
  </li>
</ul>

This way you can finally avoid writing an ugly template to show the selected item, the first and last items, submenus, ...

The bulk of the documentation can be found in the doc directory.

What now?

Follow the tutorial in doc/01-Basic-Menus.md and doc/02-Twig-Integration.md to discover how KnpMenu will rock your world!

Find all available documentation at doc/.

Maintainers

This library is maintained by the following people (alphabetically sorted) :

Credits

This bundle was originally ported from ioMenuPlugin, a menu plugin for symfony1. It has since been developed by KnpLabs and the Symfony community.

knpmenu's People

Contributors

althaus avatar b4rb4ross4 avatar bamarni avatar bchoquet-heliopsis avatar burki avatar chris8934 avatar dbu avatar derrabus avatar doncallisto avatar franmomu avatar garak avatar hason avatar havvg avatar jfsimon avatar magdicom avatar mbontemps avatar ndm2 avatar nek- avatar nicolasmure avatar oskarstark avatar preimers avatar pzaloznyi avatar sagikazarmark avatar sebastianljunggren avatar seferov avatar stof avatar tacman avatar u01jmg3 avatar weaverryan avatar wouterj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

knpmenu's Issues

style root ul element and add html to label

Just two questions. I dont see the options for:

  • adding html to label of an menu item, for now it displays itself as raw html.
  • adding atributes to root UL seems not working, for example I've tried to do:
        $menu = $factory->createItem('root');
        $menu->setAttribute('class', 'nav nav-tabs nav-stacked main-menu');

and ul is without the added class.

Any help would be appriciated. Thanks!

RouteVoter doesn't support parameters converted with ParamConverter

When using a parameter name different then id in your route, like:

/**
 * @Route("/producer/{producer}/production")
 */
class ProductionController extends Controller
{
    /**
     * @Route("/")
     */
    public function indexAction(Producer $producer) {}
}

The Knp\Menu\Silex\Voter\RouteVoter currently breaks on this, because it compares the current value from $this->request->attributes->get($name) against the value in $parameters[$route]:

    foreach ($routes as $testedRoute) {
        if ($route !== $testedRoute) {
            continue;
        }

        if (isset($parameters[$route])) {
            foreach ($parameters[$route] as $name => $value) {
                if ($this->request->attributes->get($name) != $value) {
                    return null;
                }
            }
        }

        return true;
    }

Now I'm a little confused whether this is a bug in Symfony or KnpMenu and how to fix this. In my example I could change the parameter name to id, but I think it's strange the name of parameter could possibly break things.

TwigRenderer display

hi, i 've created a customs template but i don't kon't how to display it.
i follow directive in https://github.com/KnpLabs/KnpMenu/blob/master/doc/02-Twig-Integration.markdown (last part about TwigRenderer )

In my bundle/Menu/builder.php i write this :

<?php

namespace Symuon\MapBundle\Menu;

use Knp\Menu\FactoryInterface;
use Symfony\Component\DependencyInjection\ContainerAware;

class Builder extends ContainerAware
{
    public function mainMenu(FactoryInterface $factory, array $options)
    {
        $menu = $factory->createItem('mainMenu');
        $menu->setCurrentUri($this->container->get('request')->getRequestUri());

        $menu->addChild('Home');
        $menu['Home']->setLabel('Back to homepage');
....
....
$twigLoader = new \Twig_Loader_Filesystem(array(
            '../vendor/KnpMenu/src/Knp/Menu/Resources/views',          
            //my template path,
        ));
        $twig = new \Twig_Environment($twigLoader);
        $menuRenderer = new \Knp\Menu\Renderer\TwigRenderer($twig, 'knp_menu.html.twig');
        echo $menuRenderer->render($menu, array('template' => 'my_menu.html.twig'));

and in my index.html, i wrote :

{{ knp_menu_render('MyBundle:Builder:mainMenu') | raw }}

and in my template (my_menu.html.twig), i wrote :

{% extends 'knp_menu.html.twig' %}
{% block spanElement %}<h3{{ _self.attributes(item.labelAttributes) }}>{{ block('label') }}</h3>{% endblock %}

So i have an error :
An exception has been thrown during the rendering of a template ("Method "mainMenu" did not return an ItemInterface menu object for menu ...

I look your code, and of course only $menu is an ItemInterface not the $menuRenderer->render($menu, array('template' => 'my_menu.html.twig'));

but i must do what ? I think in my index.html, the call not be this but i must what instead. in your doc, you say nothing about that (or i d'on't understand).

thank you to help a beginner in Symfony
in other way, i like your bundle ;) it's a great job !

[composer] namespace not registered

Hi,
When running composer install or update command, I realised that the namespace was not automatically registered in /vendor/.composer/autoload_namespaces.php.

I know it sounds like a composer problem, but to me it might be a composer.json one :) . Still trying to figure out why though...

Displaying menu for a certain level in the tree

No matter what level the current page is, I am displaying all the level 1 items across the top of the page, then all the level 2 items in a separate LHS col menu.

This doesn't seem to be straight forward as there is no helper to render a menu at a certain level, and no means to easily return e.g. the level 2 ancestor for the current page, in order to use this to create the menu.

Currently in order to achieve this, I am working up the provided breadCrumb array and testing for the level at each point, only rendering the LHS menu when I find the ancestor with the required level.

This is really messy in twig... clearly not the right way to go about it.

So I am wondering about whether to add methods to the menuItems class to return information regarding ancestors.

e.g. would it be useful to have

/**
 * @param int $level     The level of the ancestor to be returned
 * @return \Knp\Menu\ItemInterface
 */
public function getAncestor($level)
{
}

Any thoughts?

Is there already an accepted way to do this kind of thing?

Removing the getCurrentItem method

I open this issue to separate the discussion about this point as I originally asked in #2 but it got a bit lost in the other part of the issue.

As mentioned previously in #2, this method is currently lying as it returns the first current item found whereas the tree could contain several item.
So I see 3 solutions:

  1. Forbid to have more than 1 current item. This would be quite hard to do in an efficient way and most people commenting on it previously thought it is valid to have several one.
  2. Remove the method
  3. Replace the method by a getCurrentItems method. This method would return an array containing all current items inside the tree of the item.

I personally think that the third option is not necessary. Implementing it using some PHP iterators would be probably more efficient as we would loop over the whole tree only when actually looping over the data instead of doing it first to create the array (and for people wanting an array absolutely, they could still use iterator_to_array).

So my personal vote would be 2

Please allow customization of list element

I found that more than often I need to inset one or more html tags between the <li> and <a> / <span> elements.
Now I can only override the label block, and no way to insert something after the <li> tag.

Here is a path:

diff --git src/Knp/Menu/Resources/views/knp_menu.html.twig src/Knp/Menu/Resources/views/knp_menu.html.twig
index 5bc74ac..53ad4a8 100644
--- src/Knp/Menu/Resources/views/knp_menu.html.twig
+++ src/Knp/Menu/Resources/views/knp_menu.html.twig
@@ -56,6 +56,7 @@
     {%- endif %}
 {# displaying the item #}
     <li{{ _self.attributes(attributes) }}>
+        {%- block listElement %}
         {%- if item.uri is not empty and (not item.current or options.currentAsLink) %}
         <a href="{{ item.uri }}"{{ _self.attributes(item.linkAttributes) }}>{{ block('label') }}</a>
         {%- else %}
@@ -66,6 +67,7 @@
                 {{ block('children') }}
             </ul>
         {%- endif %}
+        {%- endblock %}
     </li>
 {% endif %}
 {% endblock %}

This change allows me to do something like this:

{% extends 'knp_menu.html.twig' %}

{%- block listElement %}
{%- if item.uri is not empty and (not item.current or options.currentAsLink) %}
<span><span>{{ parent() }}</span></span>
{%- else %}
<span>{{ parent() }}</span>
{%- endif %}
{%- endblock %}

Small change (2 lines :) ) that allow lots of customization, can you apply that change?

Causing issue with capifony deploy

I'm sorry if this is the wrong place for this issue, but for the last day or so I haven't been able to do a "cap deploy" - it always bombs out when it gets to the KnpMenu, giving the following error:

Cloning into /var/www/vhosts/MY_HOST/releases/20111110220445/vendor/KnpMenu...
error: SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed while accessing https://github.com/knplabs/KnpMenu.git/info/refs

Do you have any idea how to fix this? Thanks

knp_menu_render_breadcrumb function

it would be great to have a breadcrumb twig function similar to the knp_menu_render for the menu.

the function should expect either the menu name and then pick the currentItem based on the menu, or expect a MenuItem from which it builds the breadcrumb.
an additional cool feature would be to pass an optional array of titles and urls to append to the breadcrumb in case there is no menu item for the last entries in the breadcrumb (e.g. consider a menu item for an overview of postings and a breadcrumb on the details page of one posting. )

currently we have this code in twig to render a breadcrumb:

{% set currentItem = knp_menu_get('main').currentItem %}
{% if currentItem %}
<div class="cmf-breadcrumb">
<ul>
    {% for title, url in currentItem.breadcrumbsArray %}
        <li><a href="{{url}}">{{ title }}</a></li>
    {% endfor %}
</ul>
</div>
{% endif %}

/cc @uwej711

MenuItem name for parent menu

Hi,

in the class MenuItem i read the following comment:

protected $name = null; // the name of this menu item (used for id by parent menu)

If it should use the name to actually prefix the parent element for a multidimensional menu, it does not work. But maybe i expect something wrong? My class for parent (ul) is named "menu_level_1", "menu_level_2" and so on (I use with the TwigRenderer). Even for another menutree. So i have the same name for alle Submenus in all menus.

Hopefully my problem is understandable. It is a very nice Bundle though ;)

Improving the way the current item is determined

Currently, the library still uses the behavior coming from KnpMenuBundle:

  • an item can be set explicitly as being (or not being) current.
  • if the flag is not set, the uri is checked against the current uri set for the item (and if there is no current uri, it is not a current item)

There is some improvements needed here:

  • there can be multiple current items in a tree so the getCurrentItem method is lying by giving only the first found (should it be removed entirely ?)
  • this part of the library should be more flexible to support other behaviors (for instance matching several uris on the same item)

Use of _self in knp_menu.html.twig

The use of _self.macro() to call the macro directly instead of importing it like {% import _self as knp_menu %} will not work anymore on Twig 2.x.

See http://twig.sensiolabs.org/doc/tags/macro.html (last note).

It is easy to correct this, but on my attempt i needed to use {% import _self as knp_menu %} on each block that uses _self, a single import on top of the file does not work.
There is any way to avoid this?

Limitation when using the TwigRenderer from elsewhere than a Twig template

Due to the way Twig works, the initRuntime method is only called the first time we load a template. So when using the renderer from elsewhere than a Twig template, we need to initialize it manually (as documented)

Passing the environment to the TwigRenderer when creating it would be the solution but it is impossible currently as it would create a circular dependency. We would need to remove the need to have it as a Twig extension to do this.

https://github.com/fabpot/Twig/issues/429 would allow getting rid of this need if it is implemented. But it would mean than (the yet-to-be-released) Twig 1.2 (assuming it is added in 1.2) will become a requirement, which is an issue for Symfony2 until it becomes the release (not an issue for Silex as it already requires using the master branch)

where is setCurrentUri?

Fatal error: Call to undefined method Knp\Menu\MenuItem::setCurrentUri()

I can't find this method anymore. Something changed? Documentation says nothing. Or am I terribly wrong?

Menu list attributes not rendered in output

The attributes for the menu list (set via $menuItem->setAttribute()) are not rendered in the html output. Only a blank ul element without any attributes appears. it seems to be an error in the the knp_menu.html.twig template. an older version of this template renders the attributes for the ul element correctly.

Add CSS classes for "branches" and "leafs"

It would be nice if KnpMenu would add classes to each li element that indicate if the element has a child menu or not. Is this a feature that is generally desirable?
At the moment I'm using a custom Twig stylesheet that achieves this:

{% block item %}
{% if item.displayed %}
{# building the class of the item #}
    {%- set classes = item.attribute('class') is not empty ? [item.attribute('class')] : [] %}
    {%- if item.current %}
        {%- set classes = classes|merge([options.currentClass]) %}
    {%- elseif item.currentAncestor %}
        {%- set classes = classes|merge([options.ancestorClass]) %}
    {%- endif %}
    {%- if item.actsLikeFirst %}
        {%- set classes = classes|merge([options.firstClass]) %}
    {%- endif %}
    {%- if item.actsLikeLast %}
        {%- set classes = classes|merge([options.lastClass]) %}
    {%- endif %}
    {# Mark item as "leaf" (no children) or as "branch" (has children that are displayed) #}
    {% if item.hasChildren and options.depth is not sameas(0) and item.displayChildren and options.branchClass is defined %}
        {%- set classes = classes|merge([options.branchClass]) %}
    {% elseif options.leafClass is defined %}
        {%- set classes = classes|merge([options.leafClass]) %}
    {%- endif %}
    {%- set attributes = item.attributes %}
    {%- if classes is not empty %}
        {%- set attributes = attributes|merge({'class': classes|join(' ')}) %}
    {%- endif %}
{# displaying the item #}
    <li{{ _self.attributes(attributes) }}>
        {%- if item.uri is not empty and (not item.current or options.currentAsLink) %}
        {{ block('linkElement') }}
        {%- else %}
        {{ block('spanElement') }}
        {%- endif %}
{# render the list of children#}
        {%- set childrenClasses = item.childrenAttribute('class') is not empty ? [item.childrenAttribute('class')] : [] %}
        {%- set childrenClasses = childrenClasses|merge(['menu_level_' ~ item.level]) %}
        {%- set listAttributes = item.childrenAttributes|merge({'class': childrenClasses|join(' ') }) %}
        {{ block('list') }}
    </li>
{% endif %}
{% endblock %}
``

Improve menu for dynamic links

Hello

I just want to know how can I use the KnpMenu with 'dynamic' link ?
When I do this (I work with Symfony2) :

    public function mainMenu(FactoryInterface $factory, array $options)
    {
        $menu = $factory->createItem('root');

        $menu->addChild('Menu 1', array('route' => '_route_1'));
        $menu->addChild('Menu 2', array('route' => '_route_2'));

        $menu['Menu 1']->addChild('Submenu 1', array(
                        'route' => '_route_submenu_1',
                        'routeParameters' => array('slug' => 'fake_slug_param')));
        $menu['Menu 1']['Submenu 1']->addChild('Another submenu', array(
                        'route' => '_another_route',
                        'routeParameters' => array('slug' => 'another_fake_param')));

        return $menu;
    }

And after render it :

{{ knp_menu_render('MAHomeBundle:Builder:mainMenu') }}

How can I just display the first level and keep the 'current' status propagation of the children ?

If I do that :

{{ knp_menu_render('MAHomeBundle:Builder:mainMenu', {'depth': 1}) }}

Only "Menu 1" and "Menu 2" will be display BUT if I am on the page with route "_another_route", "Menu 1" will not have 'current_ancestor' class ...

Is there a solution?

Ps : sorry for my bad english ...

[HELP] Integration of KnpMenu childrenAttributes with Twig

Hi,

I have implemented a first time KnpMenu like that https://github.com/cedriclombardot/AdmingeneratorGeneratorBundle/blob/master/Menu/DefaultMenuBuilder.php#L25 but due to last change with childrenAttributes i have set

<?php
$menu = $this->factory->createItem('root', array('childrenAttributes' => array('id' => 'main_navigation', 'class'=>'menu')));

instead of

<?php
$menu = $this->factory->createItem('root');
$menu->setAttributes(array('id' => 'main_navigation', 'class'=>'menu'));

But when i add {{ dump(item.childrenAttributes) }} into knp_menu.html.twig Line 17 twig tell me thats an empty array !

What i miss to update ?

Thanks in advance

Creating menuitem with entity name

i'm trying to create a menuitem with a special character:

$menu['Catalogus']->addChild('Categorieën', array('route' => 'cats'));

After rendering the following HTML is generated: "Categorie&euml;n". Is there a special way to accomplish this?

Release a new tag

Since the last stable release lots of stuff happened, please release a new minor version.

Why Twig filters and not functions?

@stof, could you elaborate a bit on why you have chosen to replace a function by a filter, ie:

{% knp_menu_render('main' } %}

has become:

{{ 'main'|knp_menu_render }}

In terms of logic, it is not intuitive to me…

Attributes are not rendered

I'm using the KnpMenuBundle, but I believe this is a defect in KnpMenu.

This is my Builder class:

class Builder extends ContainerAware
{
    public function sidebarMenu(FactoryInterface $factory)
    {
        $menu = $factory->createItem('root');
        $menu->setAttribute('data-foo', 'bar');
        $menu->setCurrentUri($this->container->get('request')->getRequestUri());
        $menu->addChild('Home', array('route' => 'homepage'));
        return $menu;
    }
}

And this is the Twig file rendering the menu:

{{ knp_menu_render('MyBundle:Builder:sidebarMenu') }}

You would expect the data-foo attribute turning up in the generated <ul>, but it's not. This worked before, but today after upgrading several packages, it's not working anymore.

My previous deps.lock:

KnpMenu 9916526
KnpMenuBundle 3a90f96

And my current deps.lock:

KnpMenu f818c58
KnpMenuBundle 462b7b4

Regarding namespace and library

Since we are begining to have many libraries, it would be good to share it under Knp\Component namespace. Maybe on comming backwards incompatible changes we could change the namespace too. or even move menu under knp-components repository hood, like referenced by user component versions are usually more stable since they are independant based on framework changes, which would not require changing versions often.

Routes Missing Base Path

I feel like I'm missing something very obvious here so apologies if this is a dumb question.

Why are the uri's generated by KnpMenu bundle missing the base path for the site?

For example, my dev copy of my project sits on http://[ip address]/[project name]/web/. The URI for my home page route is being generated as /, and so the menu item is sending me to http://[ip address]/.

How can I get KnpMenu Bundle to include the base path for the site in the paths it generates?

How to display children, if parent is current.

Hi,

Loving the library here, stopped me porting my Symfony 1.4 plugin over so thanks!

One thing I can't work out though, is if you define a few menu items, and some of them have children, how can you render the children of only the current menu item?

$factory = new MenuFactory();
$menu = $factory->createItem('My menu');
$menu->addChild('Home', array('uri' => '/'));
$menu->addChild('Comments');

$menu['Comments']->setUri('/comments');
$menu['Comments']->addChild('My comments', array('uri' => '/my_comments'));

I only want My Comments (and it's siblings ul) to be rendered if Comments is the active menu item.

Any ideas?

Setting parent items as current when a child is matched

As usually the matching is done in sync with the rendering, it looks too late to do this once an item is matched.

Maybe we could introduce an option to the voters to make them check recursively? With some cache of course.

Or maybe it is already possible and I'm missing something?

Thx

root element 'class' attribute not rendered for separate children menus

You can use the class attribute on a root element to define the class for the menu's UL wrapper. So a menu that includes the root element will have the desired class.

However if you choose in a template to only render a child menu (so doesn't include that root element) then you seem to loose the ability to control that UL class.

Is there a way around this?

getBreadcrumbsArray is broken if a label is used twice in a path

There is absolutely no constraint about labels in KnpMenu. But while working on #45, I figured that the label is used as key in the return value of getBreadcrumbsArray, meaning the method is totally broken when a label is used twice in a path in the tree.

Fixing it would require a BC break as the bug comes from the design chosen for the method (which still comes from ioMenuPlugin)

SSL certificate problem

Following the install instructions at:

http://sonata-project.org/bundles/admin/master/doc/reference/installation.html

I get:

Installing/Updating KnpMenu
Cloning into /home/semateos/domains/core2.semateos.dev/vendor//knp/menu...
error: SSL certificate problem, verify that the CA cert is OK. Details:

See the more trace here:

Installing/Updating MenuBundle
Cloning into /home/semateos/domains/core2.semateos.dev/vendor//bundles/Knp/Bundle/MenuBundle...
remote: Counting objects: 1429, done.
remote: Compressing objects: 100% (604/604), done.
remote: Total 1429 (delta 760), reused 1360 (delta 701)
Receiving objects: 100% (1429/1429), 195.97 KiB, done.
Resolving deltas: 100% (760/760), done.
HEAD is now at a5fbd81 Added the build status in the Readme
Installing/Updating KnpMenu
Cloning into /home/semateos/domains/core2.semateos.dev/vendor//knp/menu...
error: SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed while accessing https://github.com/knplabs/KnpMenu.git/info/refs

fatal: HTTP request failed
sh: line 0: cd: /home/semateos/domains/core2.semateos.dev/vendor//knp/menu: No such file or directory

Offset parameter to render menu items starting at a certain depth

Hi

Just wondered if it is possible to render a menu given a certain offset, as opposed to limiting the depth with the depth parameter. I guess a possibility would be to implement my own renderer, for example to render only a submenu (>=2nd level) of a given current item.

Thanks for your response.

When will be stable 2.0.* version released

Hi there,

I have KnpMenu depedency in some projects and libs and because of the current 2.0 is in dev I'm forced to have projects in dev minimal stability.

Thanks for response.

Wilcard matching.

Would be a good thing if it was possible to do wilcard matching especially for tabbed navigation where you have an "Article" tab but more than one absolute url like "/article" "/article/12"

Custom template

Hi,

Maybe it's not an issue but i don't understand how to use a custom template through the twig function.

Is there a working example somewhere ?

Consider adding a renderer marked as default in the RendererProvider

This would allow rendering a template this way:

{{ 'main'|knp_menu_render }}

As people will likely use a given renderer in their projects, it would be easier.

If this is implemented, we should eventually consider switching the order of th arguments to pass the options before the renderer name as changing the options could be more common than changing the renderer.

What do you think about such feature ?

Composer stange deps loops ?!

Hi,

I ve the next message :

`Initializing PEAR repository http://pear.phing.info
Packages names will be prefixed with: pear-phing/                                                        Installing dependencies from lock file           Your requirements could not be solved to an installable set of packages.

        Problems:
                - Problem caused by:
                        - Package "cedriclombardot/admingenerator-generator-bundle-9999999-dev" contains the rule cedriclombardot/admingenerator-generator-bundle requires knplabs/knp-menu-bundle (== 9999999-dev). Any of these packages satisfy the dependency: knplabs/knp-menu-bundle-9999999-dev, knplabs/knp-menu-bundle-9999999-dev.
                        - Package "knplabs/knp-menu-bundle-9999999-dev" contains the rule knplabs/knp-menu-bundle requires knplabs/knp-menu ([> 1.9999999.9999999.9999999, < 2.0.9999999.9999999]). Any of these packages satisfy the dependency: knplabs/knp-menu-2.0.9999999.9999999-dev (alias of 9999999-dev).
                        - Package "knplabs/knp-menu-bundle-9999999-dev" contains the rule knplabs/knp-menu-bundle requires knplabs/knp-menu ([> 1.9999999.9999999.9999999, < 2.0.9999999.9999999]). Any of these packages satisfy the dependency: knplabs/knp-menu-2.0.9999999.9999999-dev (alias of 9999999-dev).
                        - learned: -knplabs/knp-menu-2.0.9999999.9999999-dev (alias of 9999999-dev)
                        - Installation request for cedriclombardot/admingenerator-generator-bundle == 9999999-dev: Satisfiable by [cedriclombardot/admingenerator-generator-bundle-dev-master, cedriclombardot/admingenerator-generator-bundle-dev-master].
                        - learned: -cedriclombardot/admingenerator-generator-bundle-9999999-dev

When i run a composer install and it works when i run composer update !! any idea ?

Multi nesting

Hi,

I've just sterted to use KnpMenu is must admin that is really handy but I have a problem with creating a multinesting. Is it possible to do something like this structure:

Parent
|- Child
|- Subchild
|- Subsubchild

Thank you.

Conversation: second argument of `ItemInterface::addChild()` is the URI

Hey guys!

@stof, wonderful work with finally moving this into a standalone library - it's been more than a year overdue in my opinion. Also, you've finally solved some of the inherent problems with the original version, in that a menu could render itself, which made things a bit messy.

I wanted to propose changing the addChild signature (and any other place that should match this signature) to have the uri as the second argument and the options array as the third. I think in most cases, I need a label and a URI (but no other options), and the current signature makes that quite long:

// current
$menu->addChild('Foooooo', array('uri' => 'http://foooooo.com'));

// proposed
$menu->addChild('Foooooo', 'http://foooooo.com');

// proposed, without label but with options (the ugliest case)
$menu->addChild('Foooooo', null, array('label' => 'Barrrrrr'));

Thoughts? Now is the time to break BC :)

The "attributes" macro doesn't allow easy override of the blocks

Am I missing something or is there a way to call the _self.attributes macro in a custom twig template ?

For the moment, I had to dupliace the marco declaration in my own template.

I would implement attributes rendering as in the form framework: a block.

Add a weight system to order items on the same branch

It would be great to add an optional weight for the items of the menu. This weight would be used when rendering the menu to order the items located in the same level of the tree.

I know that at the moment if I want an item at the end of the list I have to add it last. But it would simplify a lot of logic in the code if we could use a weight system.

ie. you want to display 5 menu items depending of the user role:

without weight system:

$root->addChild('menu.item1', array('route' => '_my_route1'));
$root->addChild('menu.item2', array('route' => '_my_route2'));

if ($security->isGranted('ROLE_A')) {
   $root->addChild('menu.item3', array('route' => '_my_route3'));
}

$root->addChild('menu.item4', array('route' => '_my_route4'));

if ($security->isGranted('ROLE_A')) {
    $root->addChild('menu.item5', array('route' => '_my_route5'));
}

with a weight system:

$root->addChild('menu.item1', array('route' => '_my_route1', 'weight' => 0));
$root->addChild('menu.item2', array('route' => '_my_route2', 'weight' => 10));
$root->addChild('menu.item4', array('route' => '_my_route4', 'weight' => 20));

if ($security->isGranted('ROLE_A')) {
   $root->addChild('menu.item3', array('route' => '_my_route3', 'weight' => 15));
   $root->addChild('menu.item5', array('route' => '_my_route5', 'weight' => 25));
}

I had a look to the options and could not find it so I guess it's not been implemented for now but I'll be happy to know that I'm wrong :)

Cheers,
Maxime

Css

Using custom template for menu, I need to generate dynamic css for elements.
How can I show generated css in tag of layout

Mark ancestor items, if active items are not rendered

Currently ancestor items are not marked correctly, if the item itself is not rendered.

Example: you want to add the top level navigation but not include every subpage. You cannot use the voters, because they are not called for hidden elements.

The current workaround is to render always the complete menu and add

.menu_level_1 {
    display: none;
}

which obviously is less than optimal.

I know, that this conflicts with #75, but maybe one could a flag, indicating whether it is ok to load the complete menu structure.

HTML in Labels

Is it possible to have labels preserve HTML.

$menu->addChild('Home', array(
            'route' => 'homepage',
            'label' => 'Home<span>Fly home</span>'
        ));

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.