Drupal:如何删除“编辑”选项在某些条件下节点的选项卡?

发布于 2024-12-26 07:02:42 字数 236 浏览 3 评论 0原文

我有一个节点表单,作者应该能够编辑它,除非满足某些条件。我想为作者删除这些条件下的“编辑”选项卡。高级用户应该仍然能够使用“编辑”选项卡。

hook_menu_alter() 函数对我不起作用,因为它只有在菜单构建时才会被调用,然后才会被放入缓存中。

我更愿意(a)在不添加另一个 contrib 模块的情况下执行此操作,以及(b)在模块级别而不是主题级别(为了安全性),但我也有兴趣听到其他方法。

I have a node form that the author should be able to edit, unless certain conditions are true. I would like to remove the "Edit" tab under those conditions, for the author. Power users should still be able to use the "Edit" tab.

The hook_menu_alter() function doesn't work for me because it only gets called when the menu gets built, before it is put into cache.

I would prefer to (a) do this without adding another contrib module and (b) at the module level, instead of the theme level (for security), but am interested in hearing other ways as well.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋风の叶未落 2025-01-02 07:02:42

您可能可以使用 规则 来执行此操作,但我个人会使用 hook_node_access() 在自定义模块:

function MYMODULE_node_access($node, $op, $account) {
  if ($op == 'edit') {
    if ($some_condition) {
      return NODE_ACCESS_ALLOW;
    }
    return NODE_ACCESS_DENY;
  }
  return NODE_ACCESS_IGNORE;
}

You can probably use Rules to do this but personally I'd use hook_node_access() in a custom module:

function MYMODULE_node_access($node, $op, $account) {
  if ($op == 'edit') {
    if ($some_condition) {
      return NODE_ACCESS_ALLOW;
    }
    return NODE_ACCESS_DENY;
  }
  return NODE_ACCESS_IGNORE;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文