Created
April 3, 2014 15:02
-
-
Save sachbearbeiter/9956012 to your computer and use it in GitHub Desktop.
D7: Comments: Get access via foo_preprocess_comment(&$variables) to the comment authors profile image from an ($user) imagefield and print it into the comment.tpl.php template.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? if (!empty($image)) : ?> | |
<img src="<?= image_style_url('mini',$image); ?>" alt="Profile image" /> | |
<?php endif; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Preprocess comment | |
*/ | |
function foo_preprocess_comment(&$variables) | |
{ | |
$comment = $variables['comment']; | |
$userID = $comment->uid; | |
if ($userID != '0') { | |
$user = user_load($userID); | |
$profileImage = field_get_items('user', $user, 'field_user_image'); | |
if ($profileImage) { | |
$variables['image'] = $profileImage[0]['uri']; | |
} else { | |
$variables['image'] = ''; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment