Return to Snippet

Revision: 40814
at February 8, 2011 10:03 by Turek


Initial Code
function MYTHEME_preprocess_node(&$vars, $hook) {
	if (isset($vars['field_author']['und']) && is_array($vars['field_author']['und'])) {
		$vars['submitted'] = t('Submitted by !username on @datetime', array(
		'!username' => MYTHEME_article_authors($vars['field_author']['und']),
		'@datetime' => date("Y-m-d H:i:s", $vars['created']) ));
	} else {
		$vars['submitted'] = t('Submitted by !username on @datetime', array(
		'!username' => t('Anonymous'),
		'@datetime' => date("Y-m-d H:i:s", $vars['created']) ));
	}
}

function MYTHEME_article_authors($uids) {
	$authors = array();
	if (count($uids)) {
		foreach($uids as $author) {
			$user = user_load($author['uid']);
			if ($user->uid) {
				$authors[] = l($user->name, 'user/' . $user->uid);
			}
		}
	}
	if (count($authors) > 1) {
		return implode(', ', $authors);
	}
	if (count($authors == 1)) {
		return $authors[0];
	}
	return t('Anonymous');
}

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

Initial Description
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__](http://drupal.org/project/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.

Initial Title
Drupal 7 Node with multiple authors

Initial Tags
php, drupal

Initial Language
PHP