的Drupal 6.x的

我有这样的模块,该模块管理四个不同的内容类型。对于这个问题,我该如何定义权限在同一模块中的每个内容?是否可能?我无法弄清楚如何定义权限每个内容类型的Cuz hook_perm必须与模块名命名,并且它没有任何参数(如hook_access $节点)对内容类型允许返回基地。以下是我想要做的 -

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',
);
.......
}

任何帮助,将不胜感激。

有帮助吗?

解决方案

通常你并不需要创建的内容类型自己的权限,作为节点模块中的 node_perm() 。对于在 hook_node_info() 声明每个内容类型,节点模块会自动创建一个固定的权限的设定,如下所示:

  $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()执行额外的权限(只要它们是唯一的),并根据需要使用那些在你的代码。

这里最重要的是,一个权限本身并不做太多 - 它只是将显示的权限页面上,允许它归因于角色的名称。他们只能通过代码成为“有意义”使用它们通过 user_access() 电话。

所以,如果,例如,你想创建一个特殊的,新的许可,您的每个内容类型的自己,你就只需要声明他们hook_perm()一次全部(这样你就不需要任何参数 - 仅返回每一个字符串允许你想创建)。

其他提示

一般而言,实施多于一种内容类型将返回所有它从hook_perm()定义的权限的模块;有没有办法知道哪个内容类型Drupal是要求执行权限。点击 Drupal的总要求,以模块的所有执行权限,这甚至不能与节点列表;有只实现权限其设置的网页的一些模块,例如

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top