The check for a username is:

if ($object->uid && $object->name) {

but my custom content type does not have a name field, so the check fails. Instead, it should call user_load() to load the user.

The code should look something like:

function theme_activity_username($object) {
    if ($object->uid) {
        if ($object->name) 
            $name = $object->name;
        else
            $name = user_load($object->uid)->name;

        // Shorten the name when it is too long or it will break many tables.
        if (drupal_strlen($object->name) > 20) {
            $name = drupal_substr($name, 0, 15) .'...';
        }

        $output = l($name, 'user/'. $object->uid, array('attributes' => array('title' => t('View user profile.'))));
    }
    else {
        $output = check_plain(variable_get('anonymous', t('Anonymous')));
    }

    return $output;
}

Comments

sirkitree’s picture

Status: Active » Closed (cannot reproduce)

If you have a custom content type provided by a module, then is should still have a ->name property... I fail to see the issue here. Please reopen if you care to explain further.