在有機組的環境中,我正在編寫一個模塊,它將阻止非組的成員的用戶將組帖子添加到該組中。drupal以編程方式禁用或刪除節點創建節點鏈接
我的模塊當前設置了必要的權限並檢測用戶是否有權限。
因此,當用戶正在查看組頁面時,我想禁用/刪除標準鏈接來創建組帖子。
在有機組的環境中,我正在編寫一個模塊,它將阻止非組的成員的用戶將組帖子添加到該組中。drupal以編程方式禁用或刪除節點創建節點鏈接
我的模塊當前設置了必要的權限並檢測用戶是否有權限。
因此,當用戶正在查看組頁面時,我想禁用/刪除標準鏈接來創建組帖子。
試試這種方法。
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"
}
這很有幫助。仍在努力,但我認爲這是我一直在尋找的解決方案。謝謝! – sisko