How to hide rating field when adding comment to own node? On my website, users can rate nodes with the Fivestar module while adding a comment. In other words, the rating field (called 'stars') is part of the comment. Now, I'd like to hide the rating field for users when they comment on their own nodes (or when they already have commented before - see: How to hide Fivestar rating field after first comment?).

How can I do that?



Edit 1: I applied this patch (patch 97 on https://drupal.org/node/189527), but my problem still isn't solved. I now have the following option at Administration > Structure > Content types > MyArticle > Comment fields:



But after clearing caches and creating new content, the rating field is still displayed when I add a new comment.



Edit 2: I sent an e-mail to the patch's author and he answered this:


  The purpose of the patch I created is to prevent a user from rating
  their own node.  I believe the problem you are having with this patch
  is that, since the fivestar field is on the comment, that the patch I
  wrote would probably reference the comment itself (as the entity id)
  instead of the node - freely allowing someone to vote.




Edit 3: I tried to solve my problem with a custom module called 'hiderating'. This is the code I'm using:

function hiderating_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  global $user;
  if ($form_id == "comment_node_stuff_form") {
   if ($form['#node']-&gt;uid == $user-&gt;uid) {
      $form['field_stars']['#access'] = 0;
      }
      else {
      $form['field_stars']['#required'] = 1;
      }
    }
}


I made the 'Stars' field not required from the interface. The code is nearly working: the 'Stars' field isn't displayed when one comments on his/her own node, but unfortunately, it isn't turned to 'Required' when one comments on someone else's node. In other words, my code's else part doesn't work properly.

How can this be fixed?
You should use unset($form['field_stars']); instead of $form['field_stars']['#access'] = 0; 

You can keep the fields as required and also remove the else condition.

So your final code would be something like this

function hiderating_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  global $user;
  if ($form_id == "comment_node_stuff_form") {
   if ($form['#node']-&gt;uid == $user-&gt;uid) {
      unset($form['field_stars']);
      }
    }
}