API page: https://api.drupal.org/api/drupal/core%21includes%21menu.inc/group/menu/8

Today I was going over this Menu and Routing topic on api.drupal.org with someone who was trying to port their D7 module's hook_menu() stuff to D8.

There was a crucial piece of information missing for this page.

Namely: if you have a named placeholder in your route path, and it's not entity-related (example: dblog page for the details of a log entry), in your Controller method, the placeholder value gets passed into the function argument with the same name.

So for instance if your path is
foo/bar/{baz}
your method needs to have $baz in order to receive the value of the placeholder as an argument.

We need to add this to the page.

Comments

jhodgdon’s picture

Note: I have assigned this to myself because I don't want to forget to do it and it really needs to be done and not get lost. That said, if someone else wants to write a patch, that would be great! I could then review and commit it.

metzlerd’s picture

Status: Active » Needs work
StatusFileSize
new813 bytes

Heres a quick patch... Decided to put this in the description of the simple controller since it appears there are many ways to deal with placeholders.

jhodgdon’s picture

Great, thanks for making that patch!

It needs a small wording update:

+ * A the placeholder '{myvar}' in the route will become the $myvar parameter to the

This sentence doesn't quite make sense... maybe "A" was supposed to be "For example,"?

metzlerd’s picture

Status: Needs work » Needs review
StatusFileSize
new822 bytes

Yep... coffee moment.... sorry.

jhodgdon’s picture

Status: Needs review » Fixed

Simple, clear, great! Thanks for noticing this, bringing it to my attention at PNW Drupal Summit, and then making a patch!! Committed to 8.0.x.

  • jhodgdon committed b56718d on 8.0.x
    Issue #2359035 by metzlerd: Add info to Routing topic about magic...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.