【问题标题】:hook_node_grants not invoked in drupal-7在 drupal-7 中未调用 hook_node_grants
【发布时间】:2015-04-18 08:14:24
【问题描述】:

我在我的模块中使用“hook_node_grants()”,但它从未运行(调用)。

注意“hook_node_access_records”是对的。

    function mymodule_node_grants($account, $op) {
      dpm($op);
      $grants = array();
      if ($op == 'view' || $op == 'update') {
        $grants['guser'] = array($account->uid);
      }
      return $grants;
    }

function mymodule_node_access_records($node) {
  if (!empty($node->guser)) {
    $grants = array();
    $grants[] = array(
      'realm' => 'guser',
      'gid' => user_load_by_name(array('name' => $node->guser))->uid,
      'grant_view' => 1,
      'grant_update' => 1,
      'grant_delete' => 1,
      'priority' => 1,
    );
    return $grants;
  }
}

【问题讨论】:

    标签: module drupal-7 admin message


    【解决方案1】:

    也许this answer 的帖子会对你有所帮助。

    总而言之,如果您以管理员身份(用户 ID:1)登录测试此代码,则不会调用 hook_node_grants

    此外,如果您通过身份验证的用户的角色启用了绕过节点访问权限,则查看某些source code不会调用该钩子。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-11
      • 1970-01-01
      • 2012-06-11
      相关资源
      最近更新 更多