Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
documentation
Priority:
Normal
Category:
Bug report
Assigned:
Issue tags:
Reporter:
Created:
10 Aug 2011 at 13:01 UTC
Updated:
29 Jul 2014 at 19:52 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
jhodgdonSounds like a good thing to include. Thanks for reporting this -- I had never heard of this functionality.
Comment #2
sven.lauer commentedRolling a first patch ... as this is rather complex functionality, and we want the information to be communicated as concisely to be possible, I expect this to need a couple of iterations ...
Comment #3
jhodgdonHmmm... After reading this documentation patch, I'm not understanding when I would use _load() vs. _to_arg(). It seems that both of them return something that replaces the wildcard in the argument list, correct? So I'm not understanding what the difference is, and the text you wrote doesn't illuminate that for me. Maybe say something like:
_load() and _to_arg() functions are similar, in that both replace wildcards with values. Use _load() when ...
Also, a punctuation issue: to punctuate "e.g." correctly, it should be:
+ * the wildcard; e.g., to render a link to the path.
Also, "user-ID" should be "user ID" without the hyphen.
Comment #4
sven.lauer commentedThank you for your feedback.
Not quite. This is what _load() does. _to_arg() returns something that replaces the wildcard in the path.
I am attaching another patch that tries to make this clearer (but the section on _to_arg() is starting to get quite long. Is there a way to do emphasis in doc comments? I simply put *asterisks* around the words I wanted to emphasize, but I doubt that is the right way to do it.
I've also included a paragraph on the arguments that _to_arg()-functions will be called with. Not sure if this is the right place (but this is a general problem, I find: There is no canonical place/way to document callback signatures).
The documentation on the callback signature for the _load() functions (and how you influence it via the
load_argumentsentry) is quite impenetrable right now, I will open a separate issue for that, though.Comment #5
sven.lauer commentedComment #7
sven.lauer commentedStupid me generated the patch backwards. This one should work.
Comment #8
sven.lauer commentedSilly me. At the very least, the info on the function signature should be a list. Will re-roll tomorrow.
Comment #9
jhodgdonI'll avoid critiquing the non-list... :)
But after reading this new explanation of the difference between load and to_arg, I'm even more confused. When is the menu system generating links...??? Maybe it's when you have tabs? Hmmm..
How about something like this:
_load() and _to_arg() functions may seem similar at first glance, but they have different purposes and are called at different times. _load() functions are called when the menu system is collecting arguments to pass to the page callback function (and other callback functions????). _to_arg() functions are called when the menu system is generating links to related paths, such as the tabs for a set of MENU_LOCAL_TASK items.
Comment #10
sven.lauer commentedOkay, I'll wait with re-rolling until we've settled on a wording here. Obviously, my powers of explanation are challenged by this task. Let me try and make this clear, maybe then you'll have an idea for a better wording.
_to_arg() functions are called in
_menu_link_map_translate()(in menu.inc) [Which has its own related doc issue, I think, see below].This function is called in two places in core: One is
_menu_translate()(also in menu.inc). The doc for this function sums it up quite nicely:This working "in reverse" is exactly what _to_arg() functions do. So, yes, local tasks are an example.
_menu_translate()is call inmenu_local_tasks(),menu_contextual_links()with the third param set to TRUE (i.e. only in these two functions is it instructed to call the _to_param() functions.The other place is
_menu_link_translate(), whose doc says:Again, the translation governed by second argument is what _to_arg() functions do. The only place this is used in core ($translate = TRUE).
So, yes, your suggested wording maybe is the right way to go. This bit of functionality is a bit exotic, but that is all the more reason to try and document it properly.
Sorry for writing so extensively, but does that clear things up?
As I said above, there also seems to be an issue with the documentation of
_menu_link_map_translate(), it says:This is incorrect, _to_arg() functions return STRINGS not objects (in contrast to load() functions.
Comment #11
sven.lauer commentedOh, and yes, the _load()ed object will be passed to call hook_menu()-callbacks instead of the corresponding path fragment.
Comment #12
jhodgdonIs there a problem with what I suggested in #9, and if so, can you just correct it?
Comment #13
sven.lauer commentedSorry, I misread your suggestion at first and then was unsure because you said you were still confused.
I guess we at least want to make clear that the _load functions work for all menu callbacks. The attached patch does that, and also turns the paragraph on the signature of _to_arg() functions into a list.
Comment #14
sven.lauer commentedP. S. The patch also applies cleanly against current D7 HEAD.
Comment #15
jhodgdonThanks for all of the iterations! I think this is ready to go into d8 and d7 now.
Comment #16
sven.lauer commentedThank YOU for you patient help!
Comment #17
dries commentedCommitted to 7.x and 8.x. Thanks.