hook_help() vs $section for Drupal 6
Hi, In an unrelated issue, we found that hook_help($section) gets called with the menu key now. So - if you have a "node/%node/edit", you get this in the help hook - if you have a "node", (which gets called with node/$nid too obviously), you don't get the $nid in the help hook The argument for this is that it is easy to provide broad help texts. The arguments against is obviously that it is very hard to provide focused help texts (like it is impossible to provide help text for a block configuration page based on $section alone). A couple of ideas popped up from Peter Wolanin and myself, so we only need to pick up the right one :) 1. Pass on $_GET['q'] simply to hook_help(). This makes it harder to provide a broad help text, as you would need to preg the dynamic parts out yourself. 2. Pass on both $_GET['q'] and the menu key to hook_help(). This would allow for both, if you wish. $section would become $path and $menu_key or something along the lines. 3. Pass on the whole menu item structure which has even more details. For people who would like to customize their help even more (although I am not sure what else can be used from the menu there). Now what is left is to pick one of these up, or suggest something better, so I can prepare a patch, and we can get this fixed soon. Gabor
It would be nice if some people would show interest in discussing this, it is really a tiny question. Or should I pick and implement a solution myself? Passing $_GET['q'] would be simplest obviously, but I am not sure you would be fine with it. I only know for sure, if you tell us your view. Gabor Gabor Hojtsy wrote:
Hi,
In an unrelated issue, we found that hook_help($section) gets called with the menu key now. So
- if you have a "node/%node/edit", you get this in the help hook - if you have a "node", (which gets called with node/$nid too obviously), you don't get the $nid in the help hook
The argument for this is that it is easy to provide broad help texts. The arguments against is obviously that it is very hard to provide focused help texts (like it is impossible to provide help text for a block configuration page based on $section alone).
A couple of ideas popped up from Peter Wolanin and myself, so we only need to pick up the right one :)
1. Pass on $_GET['q'] simply to hook_help(). This makes it harder to provide a broad help text, as you would need to preg the dynamic parts out yourself.
2. Pass on both $_GET['q'] and the menu key to hook_help(). This would allow for both, if you wish. $section would become $path and $menu_key or something along the lines.
3. Pass on the whole menu item structure which has even more details. For people who would like to customize their help even more (although I am not sure what else can be used from the menu there).
Now what is left is to pick one of these up, or suggest something better, so I can prepare a patch, and we can get this fixed soon.
Gabor
Gabor, node module is already returning help based on the values of arg(): http://drupal.org/node/125279 -Peter On 6/15/07, Gabor Hojtsy <gabor@hojtsy.hu> wrote:
It would be nice if some people would show interest in discussing this, it is really a tiny question. Or should I pick and implement a solution myself? Passing $_GET['q'] would be simplest obviously, but I am not sure you would be fine with it. I only know for sure, if you tell us your view.
Gabor
Gabor Hojtsy wrote:
Hi,
In an unrelated issue, we found that hook_help($section) gets called with the menu key now. So
- if you have a "node/%node/edit", you get this in the help hook - if you have a "node", (which gets called with node/$nid too obviously), you don't get the $nid in the help hook
The argument for this is that it is easy to provide broad help texts. The arguments against is obviously that it is very hard to provide focused help texts (like it is impossible to provide help text for a block configuration page based on $section alone).
A couple of ideas popped up from Peter Wolanin and myself, so we only need to pick up the right one :)
1. Pass on $_GET['q'] simply to hook_help(). This makes it harder to provide a broad help text, as you would need to preg the dynamic parts out yourself.
2. Pass on both $_GET['q'] and the menu key to hook_help(). This would allow for both, if you wish. $section would become $path and $menu_key or something along the lines.
3. Pass on the whole menu item structure which has even more details. For people who would like to customize their help even more (although I am not sure what else can be used from the menu there).
Now what is left is to pick one of these up, or suggest something better, so I can prepare a patch, and we can get this fixed soon.
Gabor
Well, node paths were just an example, as these are what people are immediately familiar with. We can certainly do custom coding at all times, when we need details from the exact path of the page, not only the already processed menu path, but I am not sure most of the time we need that. Now in Drupal 6: $_GET['q'] | hook_help() $section parameter -----------------------------------+----------------------- node/1/view | node/% node/1/edit | node/%/edit user/1 | user/% admin/build/block/list/chameleon | admin/build/block/list/chameleon admin/build/block/configure/user/1 | admin/build/block/configure The problem with the help hook parameter is that it is neither identical to what is defined in the menu hook, neither identical to the $_GET['q'] value, it is something different. Help hook authors need to resort to custom coding to get around these problems. Gabor Peter Wolanin wrote:
Gabor, node module is already returning help based on the values of arg():
-Peter
On 6/15/07, Gabor Hojtsy <gabor@hojtsy.hu> wrote:
It would be nice if some people would show interest in discussing this, it is really a tiny question. Or should I pick and implement a solution myself? Passing $_GET['q'] would be simplest obviously, but I am not sure you would be fine with it. I only know for sure, if you tell us your view.
Gabor
Gabor Hojtsy wrote:
Hi,
In an unrelated issue, we found that hook_help($section) gets called with the menu key now. So
- if you have a "node/%node/edit", you get this in the help hook - if you have a "node", (which gets called with node/$nid too obviously), you don't get the $nid in the help hook
The argument for this is that it is easy to provide broad help texts. The arguments against is obviously that it is very hard to provide focused help texts (like it is impossible to provide help text for a block configuration page based on $section alone).
A couple of ideas popped up from Peter Wolanin and myself, so we only need to pick up the right one :)
1. Pass on $_GET['q'] simply to hook_help(). This makes it harder to provide a broad help text, as you would need to preg the dynamic parts out yourself.
2. Pass on both $_GET['q'] and the menu key to hook_help(). This would allow for both, if you wish. $section would become $path and $menu_key or something along the lines.
3. Pass on the whole menu item structure which has even more details. For people who would like to customize their help even more (although I am not sure what else can be used from the menu there).
Now what is left is to pick one of these up, or suggest something better, so I can prepare a patch, and we can get this fixed soon.
Gabor
Peter Wolanin wrote:
Gabor, node module is already returning help based on the values of arg():
-Peter
But that's not a good thing, right? http://api.drupal.org/api/5/function/arg :
Avoid use of this function where possible, as resulting code is hard to read. Instead, attempt to use named arguments in menu callback functions.
My experience with Drupal so far has been limited to the API, so I don't know how things like this are handled in core. But I do know how much I used arg() in my first attempts, and how much I would regret it when having to revisit that code. It is faintly similar to the "Accumulate and Fire" antipattern. If the help hook could be improved to the point where it doesn't need any workarounds in core... Also, here's one wild idea that I thought of when I read the other three: Would it be at all sensible to pass the menu key ("node/%/edit") and a separate array with all the variable values, in order: ($nid)? -- Aran
participants (3)
-
Arancaytar Ilyaran -
Gabor Hojtsy -
Peter Wolanin