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.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | simple-route-placeholder-2359035-4.patch | 822 bytes | metzlerd |
| #2 | simple-route-placeholder-2359035-2.patch | 813 bytes | metzlerd |
Comments
Comment #1
jhodgdonNote: 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.
Comment #2
metzlerd commentedHeres 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.
Comment #3
jhodgdonGreat, thanks for making that patch!
It needs a small wording update:
This sentence doesn't quite make sense... maybe "A" was supposed to be "For example,"?
Comment #4
metzlerd commentedYep... coffee moment.... sorry.
Comment #5
jhodgdonSimple, 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.