flobb / FlobFoundationBundle

Integrates the features of the responsive framework Foundation, from ZURB (thanks guys), into Symfony by providing templates, Twig extensions, services and commands. - DISCONTINUED
http://florianbelhomme.com/flobfoundationdemobundle/
MIT License
48 stars 10 forks source link

Breadcrumb : problem with second level childrens #19

Closed QuentinLemCode closed 9 years ago

QuentinLemCode commented 9 years ago

Hello everyone

I am a pretty beginner on Symfony, and i'm using this bundle for menu and breadcrumb on an application i'm currently working on. But the breadcrumb don't display the second child of the root.

Here is the code of my menu builder :

    public function mainMenu(Request $request, SecurityContext $securityContext)
    {
        $menu = $this->factory->createItem('Corsaire')->setExtra('menu_type', 'topmenu')->setChildrenAttribute('class', 'right');
        $menu->addChild('Accueil', array('route' => 'silca_corsaire_support_accueil',
                                         'extras' => array('divider_prepend' => true, 'icon' => 'home' )));    
        $menu->addChild('Referentiel', array('route' => 'silca_corsaire_referentiel_accueil',
                                             'extras' => array('divider_preprend' => true, 'icon' => 'bars')))
                ->setExtra('divider_prepend', true);
                $menu['Referentiel']->addChild('Ajouter une application', array('route' => 'silca_corsaire_referentiel_ajout'))
                    ->setDisplay(true)
                ->addChild('Modifier une application', array('route' => 'silca_corsaire_referentiel_modifier', 'routeParameters' => array('codeApp' => 0)))
                    ->setDisplay(false)
                ->addChild('Supprimer une application', array('route' => 'silca_corsaire_referentiel_supprimer'))
                    ->setDisplay(false);
        $menu->addChild('Connexion')->setDisplay(false);
        $user = $securityContext->getToken()->getUser();
        if( $securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED') )
        {
            $menu->addChild('Utilisateur', array('label' => $user->getPrenom().' '.$user->getNom(), 'uri' => '#'))
                    ->setAttribute('dropdown', true)
                    ->setDisplay(true)
                    ->setExtras(array('divider_prepend' => true, 'icon' => 'user'));
            $menu['Utilisateur']->addChild('Se déconnecter', array('route' => 'fos_user_security_logout'))->setExtra('icon', 'power-off');
        }
        return $menu;
    }

Sorry for this dirty piece of code, but i'm working on it !

When I open the route silca_corsaire_referentiel_ajout, the breadcrumb show this : bcprob

But it should display "CORSAIRE / REFERENTIEL / AJOUTER UNE APPLICATION"

The others links ('silca_corsaire_referentiel_modifier' and 'silca_corsaire_referentiel_supprimer') don't show the correct breadcrumbs too.

Thanks for your help

flobb commented 9 years ago

Hello,

Which version of this bundle are you using ? The 1.0.5 or dev-master ? Which version of KnpMenuBundle are you using ?

Can you add your routing.yml for thoses routes ?

Thx

QuentinLemCode commented 9 years ago

Hello,

Thanks for reply, I'm using your bundle on the branch dev-master, and knp-menu 2.0 Here's my routing.yml :

silca_corsaire_referentiel_accueil:
    path:     /
    defaults: { _controller: SilcaCorsaireReferentielBundle:Referentiel:index}

silca_corsaire_referentiel_ajout:
    path:     /Ajout
    defaults: { _controller: SilcaCorsaireReferentielBundle:Referentiel:add}

silca_corsaire_referentiel_modifier:
    path:     /Modifier/{codeApp}
    defaults: { _controller: SilcaCorsaireReferentielBundle:Referentiel:edit}

silca_corsaire_referentiel_supprimer:
    path:     /Supprimer
    defaults: { _controller: SilcaCorsaireReferentielBundle:Referentiel:delete}

silca_corsaire_referentiel_fill:
    path:     /Remplir
    defaults: { _controller: SilcaCorsaireReferentielBundle:Referentiel:fill}
flobb commented 9 years ago

I try your menu and your routing and i can not reproduce this bug.

For the url : http://dev.flobdev.local/app_dev.php/Ajout issue-19

Maybe you don't have the last version of the bundle ? try a composer update. You shouln't use the dev-master for production.

PS : If you are using the 2.6 version of SF, you shouldn't use the SecurityContext $securityContext, try to use the security.token_storage. Cf : http://symfony.com/blog/new-in-symfony-2-6-security-component-improvements .

PS2 : $user = $securityContext->getToken()->getUser(); Be careful with this, the token and/or the user can be null, this line can throw exceptions. You can move it after the line if( $securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED') ), if the grant pass, the user should be here ;)

QuentinLemCode commented 9 years ago

Thank you for your advices ! I will update my code tomorrow. I already updated the bundle to the latest version (with pagerfanta) but the bug was always here.

I think the problem come from the matcher of KNP. I was using an overrided matcher because i don't want to show add/edit/delete pages in the top menu but the "Referentiel" item must have the "active" class and the breadcrumb should show this. However, i commented out the lines in services.yml and the problem was always here :(

I will look further and come back tomorrow

PS : This line in the doc don't work : $menu->setCurrentUri($request->getBaseUrl().$request->getPathInfo());

flobb commented 9 years ago

setCurrentUri was a method from KNP menu 1.x. Now, in the template, the matcher give you the current item, in the menu template you have {%- if matcher.isCurrent(item) %}

QuentinLemCode commented 9 years ago

Okay i have played a bit with xdebug Found the problem, I forget that I have used the setCurrent method in my controller :-1:

Sorry for issue, and thank for your help.

However, I need to find a trick to show the entire breadcrumb whereas the menu show only "Referentiel" as active and don't display dropdown.

QuentinLemCode commented 9 years ago

Solved with a ->setDisplayChildren(false) on "Referentiel" item :)