1

Drupal 6.x钩多个内容类型

我有这个模块管理四种不同的内容类型。对于这个问题,我如何为同一模块中的每个内容定义权限?这甚至有可能吗?我不知道如何定义每种内容类型的权限cuz hook_perm必须用模块名称命名,并且它没有任何参数(如hook_access $ node)以基于内容类型返回许可。这是我想怎么做 -

function mymodule_perm() 
{ 
if(content1)  
return array(
    'create content1 node', 
    'edit content1 nodes', 
    'delete content1 nodes', 
); 
if(content2)  
return array(
    'create content2 node', 
    'edit content2 nodes', 
    'delete content2 nodes', 
); 
if(content3)  
return array(
    'create content3 node', 
    'edit content3 nodes', 
    'delete content3 nodes', 
); 
....... 
} 

任何帮助将不胜感激。

回答

6

通常情况下,您不需要自己为内容类型创建权限,因为节点模块在node_perm()中为您执行此操作。

$perms[] = 'create '. $name .' content'; 
    $perms[] = 'delete own '. $name .' content'; 
    $perms[] = 'delete any '. $name .' content'; 
    $perms[] = 'edit own '. $name .' content'; 
    $perms[] = 'edit any '. $name .' content'; 

除此之外,你可以声明任意数量的额外的权限在你的模块hook_perm()执行(只要:对于在hook_node_info()声明每个内容类型,如下所示的节点模块会自动创建一个固定的权限集它们是独一无二的),并根据需要在代码中使用它们。

这里最重要的是权限本身并没有多大作用 - 它只是一个名字,会显示在权限页面上,允许它被归为角色。他们只会通过调用user_access()调用它们的代码变得“有意义”。因此,如果您想为您自己的每种内容类型创建一个特殊的新权限,那么您只需立即在hook_perm()中声明它们(所以您不需要任何参数 - 只需返回一个字符串每个许可你想创建)。

+0

我是如何错过每个内容的权限字符串可以作为整个字符串返回!谢谢一堆。 – Andrew 2010-06-12 14:15:55

1

一般而言,实现多种内容类型的模块将返回它从hook_perm()定义的所有权限;没有办法知道Drupal的哪些内容类型要求实现的权限。
Drupal一直向模块询问所有已实施权限的列表,这些权限甚至与节点无关;例如,有一些模块仅为其设置页面实施权限。

+0

Ya没有办法知道cuz hook_perm没有像其他钩子那样的参数来知道哪个节点正在被请求权限。 – Andrew 2010-06-22 14:11:43