在有机群组的上下文中,我正在编写一个模块,该模块将阻止非群组成员的用户将群组帖子添加到该群组中。
我的模块当前设置了必要的权限并检测用户是否具有权限。
因此,当用户查看群组页面时,我想禁用/删除标准链接以创建群组帖子。
在有机群组的上下文中,我正在编写一个模块,该模块将阻止非群组成员的用户将群组帖子添加到该群组中。
我的模块当前设置了必要的权限并检测用户是否具有权限。
因此,当用户查看群组页面时,我想禁用/删除标准链接以创建群组帖子。
试试这个方法。
function mymodule_menu_alter(&$items) {
global $user;
// Perform code for finding out users permissions.
// lets suppose we set true or false to $restricted after all
if ($restricted && isset($items['node/add/yourtype'])) {
$items['node/add/yourtype']['access arguments'] = FALSE;
// or unset($items['node/add/yourtype']) to remove item for user
}
}
如果我理解正确,您不希望某些用户创建内容类型。
所以步骤是:
1)创建一个菜单挂钩。
// Here we make sure if the user goes to for creating this node type
// we can use the appropriate call back function to stop it.
function yourmodoule_menu() {
$items = array();
$items['node/add/page'] = array(
'page arguments' => array('yourmodule_additional_actions'),
'access arguments' => array('administer create content')
);
}
2)然后制作一个权限挂钩以确保只有某些用户拥有此权限。
// drupal will only allow access to to path 'node/add/page' with people
// who have access given by you.
function yourmodule_permission() {
return array(
'add content' => array(
'title' => t('Administer create conent'),
'description' => t('Perform administration tasks and create content')
)
)
}
3)为那些有权限的用户编写你的代码。
// Only affter they have this permisson drupal will allow them access
// to the below function.
function yourmodule_additional_actions() {
// this code will only execute if the user has the permission
// "Administer create conent"
}