/**
 * 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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cybermache created an issue. See original summary.

cybermache’s picture

I'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.

/**
 * Menu title callback.
 */
function homebox_build_title($title) {
-  return t(check_plain($title), array('@user' => $GLOBALS['user']->name));
+  return t(check_plain($title));
}
drumm’s picture

Switching 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”.

cybermache’s picture

I think your solution would work great. Or maybe checking if a user name exists before returning the title?

/**
 * Menu title callback.
 */
function homebox_build_title($title) {
+ $name = $GLOBALS['user']->name;
+ if (!empty($name)):
-   return t(check_plain($title), array('@user' => $GLOBALS['user']->name));
+  return t(check_plain($title) array('@user' => $name));
+ else:
+  return t(check_plain($title);
+ endif;
}

The main point I think is that Anonymous is not being taken into account with this function and should be.

Jamesap’s picture

Reusing some code inside format_username.

drumm’s picture

Why not call format_username() instead of copying code out of it?

SylvainM’s picture

Status: Active » Needs review
FileSize
1.24 KB

Well, 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.

jcisio’s picture

Version: 7.x-2.0-rc3 » 7.x-2.x-dev
FileSize
891 bytes

New 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.

  • drumm committed 3879d22 on 7.x-2.x authored by jcisio
    Issue #2790005 by SylvainM, Jamesap, jcisio: Fix notice in...
drumm’s picture

Status: Needs review » Fixed

Looks great, committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.