0

我的评论有一个名为“额外”的字段。当查看评论的用户写下它时,我试图隐藏它。这是我的自定义模块:

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

为什么这不起作用,实现我的目标的正确方法是什么?

4

2 回答 2

1

事实证明,这段代码有效:

function mymodule_comment_view($comment) {
  global $user;
  if ($comment->uid == $user->uid){
    $comment->content['field_extra']['#access'] = FALSE;
  }
}
于 2014-02-09T15:21:36.743 回答
0

您是否记得将函数名称的“挂钩”部分更改为您的模块名称?

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

其余的代码应该可以工作。您不需要通过引用传递 $comment,因此如果您仍然有它,请再次删除“&”字符。

于 2014-02-09T15:13:02.040 回答