如何创建自定义访问功能以在 Drupal 中编辑节点类型?

发布于 2024-10-03 19:20:11 字数 583 浏览 2 评论 0原文

我有一个节点类型,只能由用户在超出其角色权限的某些情况下编辑。我正在自定义模块中执行此操作。

我想删除甚至查看编辑选项卡的功能,而不仅仅是向表单添加验证功能,以便在提交表单后提醒用户。

我需要添加某种访问功能。有人知道该怎么做吗?

提前致谢。

--更新--

我现在有两种可行的方法。

1)使用hook_nodeapi:

function mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch($op) {
    case 'prepare':
      if(!mymodule_access_function($node)) {
        $_REQUEST['destination'] = 'my_access_denied_page';
        // rest of function

2)我可以使用hook_menu_alter将访问回调函数插入到菜单项中。

就我的目的而言,2 更有意义。我想我会拼出 (1) 的代码,因为这是本页给出的答案并且它有效。

I have a node type that should only be edited by users under certain circumstances that go beyond the permissions their role has. I am doing this in a custom module.

I would like to remove the ability to even see the edit tab, and not just add a validation function to the form that will alert the user after the form is submitted.

I need to add some sort of access function. Anyone know how to do this?

Thanks in advance.

--Update--

I now have 2 ways that should work.

1) Using hook_nodeapi:

function mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch($op) {
    case 'prepare':
      if(!mymodule_access_function($node)) {
        $_REQUEST['destination'] = 'my_access_denied_page';
        // rest of function

2) I can insert a access callback function into the menu item using hook_menu_alter.

For my purposes, 2 makes more sense. I thought I would spell out the code for (1) though since that was the answer given on this page and it works.

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

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

发布评论

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

评论(2

人事已非 2024-10-10 19:20:11

对于选项卡可见性,您可以在任何地方更改主题输出,从模块挂钩到主题模板或 CSS 补丁。根据数据可见性和性能问题的要求,某些解决方案比其他解决方案更好。我们需要有关您需要何种处理的更多详细信息。

要访问,hook_nodeapi() $op'prepare',此时针对 $node 运行您的自定义代码,并决定您想要执行的操作(例如如果不存在要求,则重定向到另一个表单,或者重定向到访问被拒绝的页面)。

编辑:重定向通常使用 $_REQUEST['destination'] = 'destination/alias' (不中断执行) 完成,有时 drupal_goto('destination/ alias') (中断执行) 是合适的,但通常不起作用。请在您的项目中跟踪重定向,因为在多个逻辑条件下,您可能最终会出现不需要的且难以调试的行为。

For the tabs visibility you can alter the themed output anywhere from a module hook to a theme template or css patch. Depending on the requirements for data visibility and performance issues some solutions are better than others. We need more details on what kind of processing you need.

For access, hook_nodeapi(), $op is 'prepare', run your custom code against $node at this point, and decide what you want to do (like redirect to another form if a requirement is not present, or to an access denied page).

Edit: Redirecting is usually done with $_REQUEST['destination'] = 'destination/alias' (does not break execution), sometimes drupal_goto('destination/alias') (breaks execution) is suitable but often it doesn't work. Please keep redirects tracked on your project, as with multiple logic conditions you may end up with unwanted and hard to debug behavior.

顾挽 2024-10-10 19:20:11

每个内容类型在 admin/user/permissions 中都有默认的权限设置,用于创建、编辑、删除节点。您可以分配给匿名或经过身份验证的用户。如果您想分配给组,请创建另一个角色并分配权限,如上所述。

Every content type has default permission settings in admin/user/permissions for creating,editing ,deleting node . You may assign to anonymous or authenticated users. If you want assign to group then create another role and assign permission as mentioned above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文