Suppose I have the following route in my ej.routing.yml file:

 path: '/user/{user}/ej_profile'
   _title: 'EJ Profile'
   _form: '\Drupal\ej\Form\User\ProfileForm'
   _role: 'authenticated'
   user: \d+

Now I want to add a menu based on the above route to Tools menu. So I use the following in ej.links.menu.yml file:

  title: 'EJ Profile'
  description: 'EJ Profile'
  route_name: ej.form.user.profile
  menu_name: tools
  weight: 100

However this gives me an exception saying: Symfony\Component\Routing\Exception\MissingMandatoryParametersException: Some mandatory parameters are missing ("user") to generate a URL for route "ej.form.user.profile".

The same works as a task entry. Basically I have a custom form that extends user profile to integrate with a third-party system and I need the user id from the url to fetch appropriate user's information.

How can I have the menu to pick route parameter from the url?

  • I think that (out of the box) only local tasks and actions pick up route parameters from the current route. – Eyal Mar 13 '17 at 1:31
  • 1
    You can try using a custom class for the menu item. And then add your route parameter as you like. – Eyal Mar 13 '17 at 1:32
  • Do you want to add multiple menu items (one for each user in the DB)? Or do you want to add a single menu item (just for the current user)? – Eyal Jan 16 '18 at 18:43

It may not be the best solution, but you could add an additional route and link to that in the menu, this route would link to something like /admin/ej_profile. Then via the controller get the current user information and redirect immediately to the correct profile form.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.