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.
/**
* Menu title callback.
*/
function homebox_build_title($title) {
return t(check_plain($title), array('@user' => $GLOBALS['user']->name));
}
User '0' has no name so the error
Notice: Undefined property: stdClass::$name in homebox_build_title() (line 337 of ../sites/all/modules/homebox/homebox.module).
shows up in the log.
Comment | File | Size | Author |
---|---|---|---|
#8 | 2790005-homebox-title-8.patch | 891 bytes | jcisio |
#7 | homebox-anonymous_title-2790005-7.patch | 1.24 KB | SylvainM |
#5 | homebox-anonymous_title-2790005-5.patch | 499 bytes | Jamesap |
Comments
Comment #2
cybermache CreditAttribution: cybermache as a volunteer commentedI'm not sure why the array call for ['user']->name exists here but removing it from that line gets rid of the log message and doesn't create any new ones that I've found yet.
Comment #3
drummSwitching to a call to https://api.drupal.org/api/drupal/includes%21common.inc/function/format_... would be a good solution here.
This exists so user-personalizable dashboards can have friendly titles like “Dries’s dashboard”.
Comment #4
cybermache CreditAttribution: cybermache as a volunteer commentedI think your solution would work great. Or maybe checking if a user name exists before returning the title?
The main point I think is that Anonymous is not being taken into account with this function and should be.
Comment #5
Jamesap CreditAttribution: Jamesap at Connect-i commentedReusing some code inside format_username.
Comment #6
drummWhy not call
format_username()
instead of copying code out of it?Comment #7
SylvainM CreditAttribution: SylvainM at Axess Open Web Services commentedWell, I added again the title key for hook_menu items, because, with drush cc all, I have MySQL errors.
I think these errors would appear too by clearing the cache in UI.
Attached patch fixes it.
Comment #8
jcisio CreditAttribution: jcisio at Axess Open Web Services commentedNew patch.
- Use format_username as suggested
- Remove check_plain(), otherwise it would be double encoded (the default callback is "t", there is no check_plain neither).
- Replace "title arguments" with "title" because "title" is required (https://api.drupal.org/hook_menu) and without "title arguments", it is the "title" by default.
- It also fixes a bug that exported homebox page order (sorted by page title) is not respected.
Comment #10
drummLooks great, committed.