Specifically, every time a comment is saved, I'd like to programatically change a comment field 'Picture' to an image field from the user who wrote the comment. I have the following custom module:
function MYMODULE_comment_presave($comment) {
$user = user_load($comment->uid);
$uid = $user->uid;
$comment->field_picture['und'][0]['fid'] = $user->field_picture['und'][0]['fid'];
}
This doesn't work correctly, because the field_picture_alt
, field_picture_width
, field_picture_title
and field_picture_height
columns in my database don't get a value (they're NULL
).
I've also tried
function MYMODULE_comment_presave($comment) {
$user = user_load($comment->uid);
$uid = $user->uid;
$comment->field_picture['und'][0]['fid'] = $user->field_picture['und'][0]['fid'];
$comment->field_picture['und'][0]['width'] = $user->field_picture['und'][0]['width'];
$comment->field_picture['und'][0]['height'] = $user->field_picture['und'][0]['height'];
$comment->field_picture['und'][0]['alt'] = $user->field_picture['und'][0]['alt'];
$comment->field_picture['und'][0]['title'] = $user->field_picture['und'][0]['title'];
}
and that works perfectly.
However, I was wondering whether I always have to set the 'alt', 'title', 'width' and 'height' values manually as above.
Is there another faster way to inherit these caracteristics from the referred image? Can I for example inherit the 'height' and 'width' from an image style?