【问题标题】:How to set custom permission for buttons or fields in Drupal?如何为 Drupal 中的按钮或字段设置自定义权限?
【发布时间】:2015-10-28 15:25:47
【问题描述】:

我为 Drupal 编写了一个模块,并且我有一些字段(按钮、图像、文本)。

我希望某些字段可以对普通用户隐藏并在管理员允许时为用户打开。

此功能是使用 “字段权限” 模块实现的。我不知道如何在我的模块中编写 PHP 代码,我可以使用 "Field Permission" 模块更改权限吗?

【问题讨论】:

    标签: php drupal drupal-7


    【解决方案1】:

    在您的模块中,您可以根据以下角色设置这些字段的#access:

    $roleId = The role id;
    // If user doesn't have the role he can't access the field .
    if (isset($user->roles[$roleId])) {
      // Deny access to the field.
      $form['FIELD_NAME']['#access'] = FALSE;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 2016-05-26
      • 2016-02-28
      • 2020-12-31
      • 2018-08-25
      相关资源
      最近更新 更多