Hi, I'm confused about how the hook_help() is structured in core modules. It's currently done like so:
function hook_help($section) {
switch ($section) {
case 'admin/help':
$output = '<p>'. t('string') .'</p>';
$output .= '<p>'. t('string') .'</p>';
return $output;
case 'admin/...':
return '<p>'. t('string') .'</p>';
case 'admin/.../...':
return t('<p>long string</p><p>another long string</p>');
}
}
Why the $output variable for the 'admin/help' pages while all others return it directly? When there are multiple paragraphs outside 'admin/help' they are embedded inside t().
Wouldn't it make more sense to just assign all cases to $output the return it outside of the switch to make it more consistent?
function hook_help($section) {
$output = '';
switch ($section) {
case 'admin/help':
$output .= '<p>'. t('string') .'</p>';
$output .= '<p>'. t('string') .'</p>';
case 'admin/...':
$output .= '<p>'. t('string') .'</p>';
case 'admin/.../...':
$output .= '<p>'. t('long string') .'</p>';
$output .= '<p>'. t('another long string') .'</p>';
}
return $output;
}
Or maybe I'm making the wrong connection here. Any thoughts?
Comments
Comment #1
dvessel commentedNote, I'm willing to clean it up but need some guidance. Which html tags are okay inside t()? Noticed a few UL tags in there too. Is this to make it easier for translators by grouping chunks of text?
Comment #2
dvessel commentedOkay, got some feedback from webchick. HTML inside t() is okay when elements are grouped together to give context. I cleaned it up a bit based on the information from http://api.drupal.org/api/HEAD/function/t and from the predominant coding pattern of what was already there. Namely, the spacing consistency.
General issues:
Module specific issues:
book.module
-Changed if conditions to case.
drupal.module
-Moved
<p>*inside* t() above<ul>for consistency.filter.module
-Moved
<p>tag out of t().--originally on line 42
node.module
-Missing closing
</p>tag.--originally on line 35
-Added
<p>tag.--originally on line 39
-Added
<p>tag.--line containing "filter_xss_admin($type->help)"
--This is output from the user changeable submission guidelines. Not likely to have
<p>on its' own.-Changed if conditions to case.
search.module
-Moved
<p>tag out of t().--originally on line 104
Extra notes:
drupal.module's help leads seems to lead to nowhere. Might be a bug.
I've raised this to critical since there are string changes from moving a few tags. It's been double checked and checked against latest head but since there are a lot of changes, I guess it better be checked by someone else.
Comment #3
webchickI like this patch, but it's not critical. A few things:
+ return $output;are not equivalent. is_numeric(arg(1)) will return FALSE, and the URL will never be node/FALSE/outline. You probably want case 'node/'. arg(1) .'/outline'
<li>s? Like in drupal_help? LIs are nested inside ULs, so it makes sense to indent them, imo.-Moved
-Moved*inside* t() above
for consistency.- it makes the patch harder to review because it's so large
- There are many different types of changes, each of which needs to be weighed for pros/cons
- It creates an "all or nothing" scenario; either all of these bugs will get fixed or none of them will
-etc.
Should be broken out into separate patches. I know it's a pain to roll and maintain 5+ different patches and it's very easy to instead just catch these things all at once as you're going through; however:
Try and keep the guideline of one type of change per patch. -- better to split out the "no-brainer" fixes into separate patches so they can get committed quickly and aren't held back by people discussing whether a +XX character bloat to the source code is worth the trade-off in consistency (which I would argue it is, but others might have differing opinions). So I'd re-roll this patch so it's only the $output changes (and anything related to making the cases consistent), and make separate patch/patches for the other minor fixes.
Comment #4
dvessel commentedDuly noted. Will re-roll into smaller patches.
The removal of ul indentation was because the majority of them didn't indent them either. :) I do agree with you though.
Comment #5
dvessel commentedUpdated patch.
1. Everything is collected into $output and is returned from a single point for all sections.
2. Case breaks added as none where there beforehand.
3. Changed if conditions to switch > case. Look at the previous comment to see which modules were affected.
It's still pretty large but that's all that was changed.
Comment #6
dvessel commentedThe changes are too close together for the separate patches to work. I'll upload another after this one gets committed.
http://drupal.org/node/101562
Comment #7
dvessel commentedUpdated for head. This patch does *not* affect the string freeze. I did add some code for the 'filter_xss_admin($type->help)' in node.module since the patch from http://drupal.org/node/101562 unconditionally added the paragraph tag. Now it will only output the html when there's content to go with it.
Besides that, it's the same as post #5 updated for latest head.
Comment #8
dvessel commentedhook_help for taxonomy.module was updated since last patch.
Patch updated for that. Anyone care to set it RTBC?
Comment #9
robertdouglass commentedWell, it makes the code look cleaner, I'll agree. I've not looked at every single help page that this affects, so I'm going to refrain from setting to RTBC. If I see the patch languishing too long I'll come back after Christmas and take a look =)
Comment #10
dries commentedLooks OK to me, but let's postpone this to D6.
Comment #11
wim leersThanks to this patch, hook_help() has changed. So this patch will need a reroll. Conversion docs are available: http://drupal.org/node/114774#hook-help.
Comment #12
dvessel commentedWhoops, this fell under the radar for me. I'll get this in before the string freeze -if one exists.
Thanks for the links and reminder Wim Leers.
Comment #13
wim leersMoving to D7.
Comment #14
wim leersCleaning up the issue queue. And I think the help system has already been revamped by now :)