sonata-project / SonataUserBundle

Symfony SonataUserBundle
https://docs.sonata-project.org/projects/SonataUserBundle
MIT License
342 stars 487 forks source link

Menu items in profile page never active #893

Closed loconox closed 4 years ago

loconox commented 7 years ago

Environment

Sonata packages

$ composer show sonata-project/*
sonata-project/admin-bundle              3.17.0 The missing Symfony Admin Generator
sonata-project/block-bundle              3.3.2  Symfony SonataBlockBundle
sonata-project/cache                     1.0.7  Cache library
sonata-project/classification-bundle     3.3.0  Symfony SonataClassificationBundle
sonata-project/core-bundle               3.3.0  Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.2.1  Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.0.2  Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.1.4  Symfony Sonata / Integrate Doctrine ORM into t...
sonata-project/easy-extends-bundle       2.2.0  Symfony SonataEasyExtendsBundle
sonata-project/exporter                  1.7.1  Lightweight Exporter library
sonata-project/formatter-bundle          3.2.1  Symfony SonataFormatterBundle
sonata-project/google-authenticator      1.1.0  Library to integrate Google Authenticator into...
sonata-project/intl-bundle               2.3.0  Symfony SonataIntlBundle
sonata-project/media-bundle              3.5.1  Symfony SonataMediaBundle
sonata-project/news-bundle               3.1.2  Symfony SonataNewsBundle
sonata-project/notification-bundle       3.1.0  Symfony SonataNotificationBundle
sonata-project/seo-bundle                2.2.0  Symfony SonataSeoBundle
sonata-project/timeline-bundle           3.1.1  Integrates SpyTimelineBundle into Sonata
sonata-project/user-bundle               3.2.3  Symfony SonataUserBundle

Symfony packages

$ composer show symfony/*
symfony/monolog-bundle     v3.1.0  Symfony MonologBundle
symfony/phpunit-bridge     v2.8.20 Symfony PHPUnit Bridge
symfony/polyfill-apcu      v1.3.0  Symfony polyfill backporting apcu_* functions to lower PHP ...
symfony/polyfill-intl-icu  v1.3.0  Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring  v1.3.0  Symfony polyfill for the Mbstring extension
symfony/polyfill-php54     v1.3.0  Symfony polyfill backporting some PHP 5.4+ features to lowe...
symfony/polyfill-php55     v1.3.0  Symfony polyfill backporting some PHP 5.5+ features to lowe...
symfony/polyfill-php56     v1.3.0  Symfony polyfill backporting some PHP 5.6+ features to lowe...
symfony/polyfill-php70     v1.3.0  Symfony polyfill backporting some PHP 7.0+ features to lowe...
symfony/polyfill-util      v1.3.0  Symfony utilities for portability of PHP codes
symfony/security-acl       v2.8.0  Symfony Security Component - ACL (Access Control List)
symfony/swiftmailer-bundle v2.5.4  Symfony SwiftmailerBundle
symfony/symfony            v2.8.20 The Symfony PHP framework

PHP version

$ php -v
PHP 7.0.14 (cli) (built: Dec  8 2016 23:34:17) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Xdebug v2.5.0, Copyright (c) 2002-2016, by Derick Rethans

Subject

On the page /profile there is a menu rendered from the block sonata.user.block.menu. The item 'Dashbord' of this menu should be active because it's the current page.

To determine which item of the menu should be active, KnpMenu use a Matcher and a collection of voters. For instance, there is a RouteVoter that should match the current route with the route linked to the menu item, but this doesn't work. In fact, there are two routes that match the uri /profile, from SonataUserBundle/Resources/config/routing/sonata_profile_1.xml, there are fos_user_profile_show and sonata_user_profile_show.

For a reason I wasn't able to find, in the matcher the current route is fos_user_profile_show whereas the item in the menu is sonata_user_profile_show. This way, the menu item is never active.

greg0ire commented 7 years ago

Is having both routes enabled really necessary?

loconox commented 7 years ago

That's the default configuration from the UserBundle. In fact, that seems to be a wroking workarround. By redefining each routes and not including sonata_profile_1.xml I solved my issue.

If fos_user_* routes are not necessary, it might be a good idea to remove them from sonata routing files ?

greg0ire commented 7 years ago

Does this answer your question?

loconox commented 7 years ago

Well, I don't know if those fos routes are used in any way, if not, I'm good.

greg0ire commented 7 years ago

The docs tell you you can safely choose to replace them with the sonata routes, don't they? They don't tell you to keep both.

loconox commented 7 years ago

Well, it says to add this in my routing.yml:

sonata_user_profile:
    resource: "@SonataUserBundle/Resources/config/routing/sonata_profile_1.xml"
    prefix: /profile

and the file sonata_profile_1.xml itself contains both routes. That's why I was wondering if there is any reason for this.

greg0ire commented 7 years ago

Oh wow that's quite weird

greg0ire commented 7 years ago

Had a look at the routes, the only difference is there name... @Bladrak , can you please explain?

Bladrak commented 7 years ago

@greg0ire it's been a long time, but I think this might have to do with preserving backwards compatibility at the time. Might not be needed anymore though.

stale[bot] commented 4 years ago

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

loconox commented 4 years ago

I'm not working on any project using sonata blocks. For me it can be closed.