Loading
Вывод вместо логина полного имени пользователя
Источник:
How to display user's fullname in Drupal По умолчанию, Drupal выводит в качестве имени пользователя его логин. Если вы хотите, чтобы вместо логина выводилась информация из другого поля профиля, нужно сделать следующее.
1. Включить стандартный модуль Profile.
2. Добавить текстовое поле profile_fullname.
3. Добавить в template.php следующий код:
function phptemplate_username($object) {
if ($object->uid && $object->name) {
// Shorten the name when it is too long or it will break many tables.
if (drupal_strlen($object->name) > 20) {
$name = drupal_substr($object->name, 0, 15) .'...';
}
else {
$name = $object->name;
}
$profile = user_load(array('uid' => $object->uid));
if ($profile->profile_fullname) {
if (drupal_strlen($profile->profile_fullname) > 20) {
$name = drupal_substr($profile->profile_fullname, 0, 15) .'...';
}
else {
$name = $profile->profile_fullname;
}
}
if (user_access('access user profiles')) {
$output = l($name, 'user/'. $object->uid, array('title' => t('View user profile.')));
}
else {
$output = check_plain($name);
}
}
else if ($object->name) {
// Sometimes modules display content composed by people who are
// not registered members of the site (e.g. mailing list or news
// aggregator modules). This clause enables modules to display
// the true author of the content.
if ($object->homepage) {
$output = l($object->name, $object->homepage);
}
else {
$output = check_plain($object->name);
}
$output .= ' ('. t('not verified') .')';
}
else {
$output = variable_get('anonymous', t('Anonymous'));
}
return $output;
}Теперь, если пользователь заполнит поле profile_fullname в своём профиле, то вместо логина будет выводится содержание этого поля. Здесь же можно поменять текст not verified, который многим не нравится.
Метки:


