[英]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? 为什么这不起作用,实现我的目标的正确方法是什么?
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? 您还记得将函数名称的“ hook”部分更改为模块名称吗?
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. 您不需要通过引用传递$ comment,因此,如果仍包含它,请再次删除“&”字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.