How to hide a field in a comment in hook_comment_view programatically? My comments have a field called 'Extra'. I'm trying to hide it when the user who's viewing the comment wrote it. This is my custom module:

function mymodule_comment_view($comment) {
  global $user;
  if ($comment-&gt;uid == $user-&gt;uid){
    unset ($comment-&gt;field_extra);
  }
}


Why isn't this working and what's the correct way to achieve my goal?
hook_comment_view(), along with most of the other entity view hooks, are typically used to add properties onto the entity object.

If you read the source for comment_build_comment(), $comment-&gt;content[] has already been built up by the time the view hook gets invoked.  So, messing with the field directly has no effect at this point.

You want to implement a template_process_comment() in your theme, or you can implement a module (which technically makes it an instance of hook_preprocess_comment().

Implement this, and then dpm($variables) inside it.  Figure out what you don't want, and then unset() it.  If the variable is printed directly from the comments template, this is is directly in $variables.  If it is in the content section, then unset the proper key in $variables['content'], which is a render tree.