开发者

Drupal Custom Node Access

开发者 https://www.devze.com 2023-01-24 01:32 出处:网络
I need some complex node acces开发者_C百科s in Drupal and I have decided to role my own module. What hooks do I need to look at to allow access to nodes. Do you have any examples.All you need is hook_

I need some complex node acces开发者_C百科s in Drupal and I have decided to role my own module. What hooks do I need to look at to allow access to nodes. Do you have any examples.


All you need is hook_access

If you want to do access control on all nodes, this can be done with a bit of tweaking. You can use hook_menu_alter to add your custom access control function to 'node/%node'. It could look like this:

function module_menu_alter($items) {
  $items['node/%node']['access callback'] = 'module_node_access';
}

function module_node_access($op, $node) {
  if ($special_case) {
    return FALSE;
  }
  elseif ($special_case_2) {
    return TRUE;
  }
  // Default, let Drupal handle it.
  return return node_access($op, $node);
}


This is something of a pain in Drupal 6 - hook_access can only tweak access on node types created by the module it's part of, and hook_node_access is new in Drupal 7.

Unfortunately, the best solution I've found for this is via a core patch that adds an access op to hook_nodeapi. Details can be found here.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号