Search code examples
phpdrupal-7fielddrupal-comments

How to hide a field in a comment 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->uid == $user->uid){
    unset ($comment->field_extra);
  }
}

Why isn't this working and what's the correct way to achieve my goal?


Solution

  • It turns out that this code works:

    function mymodule_comment_view($comment) {
      global $user;
      if ($comment->uid == $user->uid){
        $comment->content['field_extra']['#access'] = FALSE;
      }
    }