Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
foreach (module_implements('help') as $module) {
$items['admin/help/' . $module] = array(
'title' => $module,
'page callback' => 'help_page',
'page arguments' => array(2),
'access arguments' => array('access administration pages'),
'type' => MENU_VISIBLE_IN_BREADCRUMB,
'file' => 'help.admin.inc',
);
}
All this needs is a title callback as far as I can tell, then it should work with a single router item.
Comments
Comment #1
Jody LynnHow's this?
Comment #3
grndlvl CreditAttribution: grndlvl commentedReroll.
Comment #4
tim.plunkettComment #5
star-szrThis needs a reroll first.
Comment #6
star-szrRerolled. I removed the unnecessary title argument, since we are not using a title callback at all. The page title is set via drupal_set_title() in help_page().
Some notes from my review:
Could use a review from one more set of eyes.
Comment #7
star-szrHere's an interdiff.
Comment #8
star-szr#6: 1618458-6.patch queued for re-testing.
Comment #9
star-szrComment #10
star-szrThis definitely needs a reroll, will get to it over the next few days.
Comment #11
star-szrThis should do it.
Comment #13
star-szr#11: 1618458-11.patch queued for re-testing.
Comment #14
andymartha CreditAttribution: andymartha commentedwell, this doesn't cause any changes to functionality, but changes the code to remove unnecessary router items. I don't often use help so I can't comment too much on how it is different but good work Cottser.
Comment #15
catchThis looks good. help_menu() needs updating to the new router system, but given this needs backport and this doesn't make that task any harder, no point doing that here.
Committed/pushed to 8.x.
Comment #16
foxtrotcharlie CreditAttribution: foxtrotcharlie commentedMy first attempt at the D7 backport. The D8 patch doesn't contain page arguments but I wasn't sure if the same would be the case for D7 so I left it in. I did remove the title like in the D8 patch.
Comment #17
dawehnerThe title is different as it is not longer handled in hook_menu(). In order to support the title properly you probably need a title callback.
Comment #18
foxtrotcharlie CreditAttribution: foxtrotcharlie commentedThanks for the feedback dawehner - I had a look at the page callback help_page($name) in help.admin.inc and it does set the title there using the module name so I thought that was enough:
But there could well be another use of the title callback that I'm missing, maybe to do with i18 or breadcrumbs?
Comment #19
dawehnerWell, you might need this for menu links.
Comment #20
foxtrotcharlie CreditAttribution: foxtrotcharlie commentedThanks for your help dawehner. I've added a title callback. It does not translate using t() because this wildcard should be the machine name of a module. I also added some text to help.admin.inc which is displayed if the wildcard from the URL does not correspond to any module name or no hook_help() is found for that module name. This may not be the most appropriate message, or even best way to go - perhaps I should use drupal_not_found()? In the D8 patch a NotFoundHttpException() is thrown and I'm not sure what the equivalent would be for D7.
Comment #21
foxtrotcharlie CreditAttribution: foxtrotcharlie commentedThis patch uses drupal_not_found() instead of the custom message when the help page doesn't exist. Also removed unnecessary whitespace. It's my first interdiff so I may not have done it right but we'll see. Was looking to replace the custom title callback with another that already existed but couldn't find anything appropriate, so left the custom one.
Comment #23
foxtrotcharlie CreditAttribution: foxtrotcharlie commentedok, something weird going on there with some code from field.api. Will figure it out and fix.
Comment #24
foxtrotcharlie CreditAttribution: foxtrotcharlie commentedI had reverted a commit I think. Trying again.
Comment #25
foxtrotcharlie CreditAttribution: foxtrotcharlie commentedUpdating issue status...
Comment #26
foxtrotcharlie CreditAttribution: foxtrotcharlie commentedTested and realised that using drupal_not_found() caused a double page not found message as well as a 'headers already sent' error. Changed to return MENU_NOT_FOUND instead (as suggested at https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_...) and this seems to work. New patch attached.
Comment #27
star-szrMinor but the @param and @return on the helper function could indicate the data type as on https://drupal.org/node/1354#types.
Good work on this @foxtrotcharlie :)
Comment #28
foxtrotcharlie CreditAttribution: foxtrotcharlie commentedThanks @Cottser. Here's an updated patch that includes the data types for the @param and @return values.
Comment #29
dawehnerShouldn't we sanitize the value? I am just curious.
Comment #30
foxtrotcharlie CreditAttribution: foxtrotcharlie commentedThanks for checking @dawehner. I think I read another issue where it was escaped twice so was trying to avoid that (see https://drupal.org/node/1137744). And maybe in this issue too: https://drupal.org/node/1555294 ?
But, now that you mention I'm not sure if that applies in this case. @Cottser was suggesting that it would be ideal if we can get rid of the title callback completely, but we weren't sure if that was possible. I will try dig into the menu system to see if I can understand better how the title callback will be used in this case - if it's passed to l() then we would want an unsanitized value, no? I am also actually not sure what MENU_VISIBLE_IN_BREADCRUMB means in practice, but I will look into it.
At least it seems clear that the title callback is not being used for displaying the page title as that's handled by drupal_set_title() in the help_page() callback in help.admin.inc.
Comment #30.0
foxtrotcharlie CreditAttribution: foxtrotcharlie commentedrouter time = router item
Comment #31
foxtrotcharlie CreditAttribution: foxtrotcharlie commentedI think we don't need to sanitize the value because when drupal calls for the title in drupal_get_title(), if the title hasn't yet been set using drupal_set_title (which itself runs it through check_plain()), drupal_get_title() gets the title using menu_get_active_title() which it then runs through check_plain(). Perhaps someone who knows the menu system well could confirm this.
Although the menu title (that we set using the new title callback) is not used as the page title because it's set by the page callback, and it is not used in the breadcrumb (because the current page is never displayed in the breadcrumb), the menu title is used by the shortcut module when you add a shortcut to the toolbar, and in our case it will just display the machine name of the module, not the actual name. I don't know if this is a shortcoming of the shortcut module ;-) but I haven't had time to investigate it.
A way to fix this in the help module would be to move the logic which sets the page title in help.admin.inc:
into our custom title callback so that it looks something like:
In this way, if the module exists, we set the title so that it is not just the machine name of the module, but the actual display name.
The updated help_page callback would then look like this:
Then I am not sure why we are using type "MENU_VISIBLE_IN_BREADCRUMB" which is a flag and not a menu type (types are listed https://api.drupal.org/api/drupal/modules%21system%21system.api.php/func...). Should we not be using "MENU_CALLBACK" as the type? There was an issue early on in D7 where MENU_CALLBACK was buggy and did not correctly display the page title (https://drupal.org/node/965272) but this was fixed - perhaps this is why the flag MENU_VISIBLE_IN_BREADCRUMB was initially used? Can I use MENU_CALLBACK instead?
Comment #32
foxtrotcharlie CreditAttribution: foxtrotcharlie commentedDiscussed this in IRC with @Cottser today and he said that it was probably beyond the scope of this issue to change the menu title to be the human readable module name. So we'll keep the patch at #29, and now just needs review - would be great if someone can confirm that we don't need to sanitise the title callback value :-)