The comments on my articles have a Fivestar field called 'Stars', but rating nodes isn't always required (see: How to hide rating field when adding comment to own node?). When the user didn't rate the node on which he/she is reacting, 0 stars (not saved in the database) are now being displayed in his/her comment, but I don't really like that.
How can I hide the stars when the user didn't vote?
Edit: I'm trying to find a workaround with flags. I've created a flag called 'Reaction on own' and a rule that flags a comment when the comment's author equals the author of the commented node. In my case, it's sufficient that the 'Stars' field isn't displayed when a comment is flagged with 'Reaction on own'. This is the code of my custom module:
function hiderating_comment_view($comment) {
$flag = flag_get_flag('reaction_on_own');
if ($flag->is_flagged($comment->cid)){
unset($comment->field_stars);
}
}
Unfortunately, this isn't working. What's going wrong?
Note: In fact, the edit above isn't entirely true in my case, because 'zero' stars appear when a user reacts on his/her article or when the user has commented before. I've provided an answer for both cases.
if ($comment == "comment_node_article") {
is incorrect hashook_comment_view
is passed the comment object, not a string in that parameter. It will never evaluate to true.