Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pretty URLs are not used when relying on MenuItem::linkToCrud and @EasyAdmin/page/content.html.twig #6499

Closed
quentint opened this issue Nov 4, 2024 · 12 comments · Fixed by #6507
Labels
bug priority: important Bugs to fix and features to implement
Milestone

Comments

@quentint
Copy link
Contributor

quentint commented Nov 4, 2024

Describe the bug
I was trying the new pretty URLs feature and activated them by adding the easyadmin.yaml config. I noticed the routes where created perfectly but were not used in my backend.

Looking around, I noticed if I opened one of them directly, without clicking on the menu items links (that were using the old/query string links), the page would load and the menu links would use the new/pretty URLs. At first I thought I had to replace all my MenuItem::linkToCrud calls with MenuItem::linkToUrl but the docs didn't say anything about that, so I dug a bit more. It turns out, when relying on the @EasyAdmin/page/content.html.twig view for the dashboard's index, the generated routes do not have the ROUTE_CREATED_BY_EASYADMIN option, and fall back to the old URLs.

Unfortunately, the tests pass because the index methods on both tests/PrettyUrlsTestApplication/src/Controller/DashboardController.php and tests/PrettyUrlsTestApplication/src/Controller/SecondDashboardController.php rely on AbstractDashboardController's index method, which uses @EasyAdmin/welcome.html.twig that does not contain any menu items (so no test checks if the URLs are pretty in this case).

To Reproduce
Make sure to rely on the base @EasyAdmin/page/content.html.twig view in your dashboard's index method.

@quentint
Copy link
Contributor Author

quentint commented Nov 4, 2024

I've set up tests in my fork to ensure it is reproducible: quentint@268e336.

@javiereguiluz javiereguiluz added bug priority: important Bugs to fix and features to implement labels Nov 4, 2024
@javiereguiluz javiereguiluz added this to the 4.x milestone Nov 4, 2024
@frankverhoeven
Copy link

Hi there, I have noticed the same, and tracked it down to the following:

  • While on a dashboard, the request attribute EA::ROUTE_CREATED_BY_EASYADMIN is not set. This causes the router to use the old URLs.
  • If I force the request attribute to true, the sidebar menu will use the pretty URLs, but some other issues arise.

Hope this helps. The pretty URLs are very.. pretty 🥰

@duha99
Copy link

duha99 commented Nov 4, 2024

First: I love the new Pretty URLs.

Adding to the Posts before:
When accessing the Pages for the first-time manually via the pretty URL, it will switch and only Pretty URLs are visible after that.
Actions Index and new work flawlessly, but on edit or detail it raises an error with entityId is not set.

I could narrow it down to the Template Building the navigation, it seems the entityId is missing to generate the URLs.

@dwgebler
Copy link

dwgebler commented Nov 6, 2024

Pretty URLS, unfortunately, seem to have just not been implemented or tested properly prior to release.
Similar to other comments in this issue, I have a very vanilla set-up of EasyAdmin where I've installed the bundle, added the easyadmin.yaml routing file, then I have a custom dashboard template that extends the default layout.html.twig.

Although I can see all my admin_ routes generated by Symfony if I run a debug on the router, when I log in to the dashboard, the old style URLs are used. If I manually navigate to e.g. /admin/someEntityName/ it loads in some cases (and the dashboard menu links then change to pretty URLs) but some entities viewing index or edit pages just gives me an error Some mandatory parameters are missing ("entityId") to generate a URL for route and these are just using the default bundle views, so it's nothing on my side.

@pfpro
Copy link
Contributor

pfpro commented Nov 6, 2024

Quoi qu’il en soit, quelle mission honorable. tant d'utilisateurs se sont plaints de l'absence de jolies URL - le but est le chemin !

bravo au vieux monde

@dwgebler
Copy link

dwgebler commented Nov 6, 2024

@javiereguiluz just upgraded to 4.14.2 and now I get the error:

An exception has been thrown during the rendering of a template ("EasyCorp\Bundle\EasyAdminBundle\Router\AdminRouteGenerator::findRouteName(): Argument #2 ($crudControllerFqcn) must be of type string, null given, called in /app/vendor/easycorp/easyadmin-bundle/src/Router/AdminUrlGenerator.php on line 330").

when trying to render my dashboard template, even if I scale that template right back down to

{% extends '@EasyAdmin/layout.html.twig' %}

{% block main %}
    <h2>Welcome</h2>
{% endblock main %}

According to the debug trace, the error is thrown on the last line I've included here:

<nav id="main-menu">{% block main_menu_before %}{% endblock %}<ul class="menu">{% block main_menu %}
{% for menuItem in ea.mainMenu.items %}

@JorickPepin
Copy link
Contributor

Hi @dwgebler, it seems to be linked to MenuItem::linkToDashboard, see #6507 (comment)

@javiereguiluz javiereguiluz reopened this Nov 6, 2024
@dwgebler
Copy link

dwgebler commented Nov 6, 2024

@JorickPepin you're correct, removing linkToDashboard results in dashboard displaying correctly with pretty URLs in 4.14.2. The inability to use linkToDashboard is a separate issue that needs fixing, though. I've not had time yet to look under the hood at why this is happening in any detail myself, hopefully @javiereguiluz or another contributor can come up with a quick fix.

@javiereguiluz
Copy link
Collaborator

@dwgebler yes, sorry about this. I'm going to try to fix that soon. Meanwhile, and I'm very sorry, disable the pretty URLs feature, and you'll be able to use it very soon. Thanks!

@dwgebler
Copy link

dwgebler commented Nov 6, 2024

@javiereguiluz really appreciate the work you've put in for pretty URLs, thank you.

@javiereguiluz
Copy link
Collaborator

We're constantly releasing new versions to fix reported bugs related to pretty URLS: https://github.com/EasyCorp/EasyAdminBundle/releases

Please, update to the latest version and report if you still face the same errors. Thanks.

@javiereguiluz
Copy link
Collaborator

We've just released a new issue (the third in the last 24 hours) to fix more issues. Please, try it and report bugs creating new issues. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug priority: important Bugs to fix and features to implement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants