Posted By

Turek on 02/08/11


Tagged

php node drupal multiple 7 authors


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

AllKnightAccess
mlangfeld


Drupal 7 Node with multiple authors


 / Published in: PHP
 

URL: http://turczynski.com/blog/2011-02-07/drupal-7-node-multiple-authors

I have to migrate from my old Drupal 5 site, that had multiple authors assigned to one node, and this is the solution for Drupal 7. First of all you will need to download References module and enable User Reference. Then go to your module (sites\all\modules\references\) and edit file user_reference\user_reference.module at line number 481 as it has an error. Change line: $query->condition($user_uid_alias, $ids, 'IN', $ids); to this: $query->condition("u.$user_uid_alias", $ids, 'IN', $ids); Now go to your theme, and edit template.php file adding this lines.

  1. function MYTHEME_preprocess_node(&$vars, $hook) {
  2. if (isset($vars['field_author']['und']) && is_array($vars['field_author']['und'])) {
  3. $vars['submitted'] = t('Submitted by !username on @datetime', array(
  4. '!username' => MYTHEME_article_authors($vars['field_author']['und']),
  5. '@datetime' => date("Y-m-d H:i:s", $vars['created']) ));
  6. } else {
  7. $vars['submitted'] = t('Submitted by !username on @datetime', array(
  8. '!username' => t('Anonymous'),
  9. '@datetime' => date("Y-m-d H:i:s", $vars['created']) ));
  10. }
  11. }
  12.  
  13. function MYTHEME_article_authors($uids) {
  14. $authors = array();
  15. if (count($uids)) {
  16. foreach($uids as $author) {
  17. $user = user_load($author['uid']);
  18. if ($user->uid) {
  19. $authors[] = l($user->name, 'user/' . $user->uid);
  20. }
  21. }
  22. }
  23. if (count($authors) > 1) {
  24. return implode(', ', $authors);
  25. }
  26. if (count($authors == 1)) {
  27. return $authors[0];
  28. }
  29. return t('Anonymous');
  30. }

Report this snippet  

You need to login to post a comment.