【问题标题】:How to hide a field in a comment programatically?如何以编程方式隐藏评论中的字段?
【发布时间】:2014-02-08 18:05:42
【问题描述】:

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

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

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

【问题讨论】:

    标签: php drupal-7 field drupal-comments


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

      • 是的,我做到了。我会在我的问题中澄清它。在此期间我找到了答案。
      猜你喜欢
      • 1970-01-01
      • 2016-03-30
      • 2010-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-21
      • 2015-03-03
      相关资源
      最近更新 更多