سؤال

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?

هل كانت مفيدة؟

المحلول

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;
  }
}

نصائح أخرى

Did you remember to change to "hook" part of the function name to the name of your module?

function MODULENAME_comment_view($comment) {
  global $user;
  if ($comment->uid == $user->uid){
    unset ($comment->field_extra);
  }
}

The rest of the code should work. You shouldn't need to pass $comment by reference, so remove the "&"-character again if you still have it in.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top