[gelöst] Span mit User-ID zu Username hinzufügen

am 13.11.2012 - 16:13 Uhr in
Hallo zusammen,
nachdem ich mir nun auf drupal.org nen Ast gesucht habe, und wenn überhaupt Ergebnisse von Drupal 6.x oder gar 5.x finde, wollte ich an dieser Stelle fragen, ob es irgendwie möglich ist, z.B. via template.php, um jeden Nutzernamen ein span mit der jeweiligen user ID zu legen. So, dass es quasi so ausschaut: Username. Ziel ist es jeden Nutzernamen individuell via CSS "targeten" zu können, um z.B. individuelle Farben für bestimmte Nutzer zu vergeben. Leider gibt es meist keine eindeutigen Klassen oder auch IDs, um das gezielt machen zu können.
Über etwaige Hilfe würde ich mich sehr freuen!
Beste Grüße vom,
Genesis
- Anmelden oder Registrieren um Kommentare zu schreiben
Ich habs mir mal wieder
am 13.11.2012 - 16:56 Uhr
Ich habs mir mal wieder selbst beantwortet. Es ist ja leider meist so, immer wenn man Hilfe sucht, dann findet man es kurz darauf selbst. :|
Ich will aber noch kurz schreiben wie ichs nun gemacht habe, wobei ich nicht mal weiß ob es der richtige, bzw. beste, bzw. richtigste (!) Weg ist. Jedenfalls habe ich es nun via template_preprocess_username gemacht. In der template.php habe ich hinzugefügt:
<?php
function themename_preprocess_username(&$variables) {
$account = $variables['account'];
$variables['extra'] = '';
if (empty($account->uid)) {
$variables['uid'] = 0;
if (theme_get_setting('toggle_comment_user_verification')) {
$variables['extra'] = ' (' . t('not verified') . ')';
}
}
else {
$variables['uid'] = (int) $account->uid;
}
// Set the name to a formatted name that is safe for printing and
// that won't break tables by being too long. Keep an unshortened,
// unsanitized version, in case other preprocess functions want to implement
// their own shortening logic or add markup. If they do so, they must ensure
// that $variables['name'] is safe for printing.
$name = $variables['name_raw'] = format_username($account);
if (drupal_strlen($name) > 20) {
$name = drupal_substr($name, 0, 15) . '...';
}
$variables['name'] = check_plain($name);
$variables['profile_access'] = user_access('access user profiles');
$variables['link_attributes'] = array();
// Populate link path and attributes if appropriate.
if ($variables['uid'] && $variables['profile_access']) {
// We are linking to a local user.
$variables['link_attributes'] = array('title' => t('View user profile.'));
$variables['link_path'] = 'user/' . $variables['uid'];
$variables['link_attributes'] = array('class' => t('uid').$variables['uid']);
}
elseif (!empty($account->homepage)) {
// Like the 'class' attribute, the 'rel' attribute can hold a
// space-separated set of values, so initialize it as an array to make it
// easier for other preprocess functions to append to it.
$variables['link_attributes'] = array('rel' => array('nofollow'));
$variables['link_path'] = $account->homepage;
$variables['homepage'] = $account->homepage;
}
// We do not want the l() function to check_plain() a second time.
$variables['link_options']['html'] = TRUE;
// Set a default class.
$variables['attributes_array'] = array('class' => array('username'));
}
?>
Via:
<?php
$variables['link_attributes'] = array('class' => t('uid').$variables['uid']);
?>
wird nun vor der Klasse "username" entsprechend uidX, z.B. uid13 angezeigt. Ich bin leider kein PHPler, weswegen das alles Trial and Error ist, aber so funktioniert es aktuell.