2011-11-29 114 views
0

在有機組的環境中,我正在編寫一個模塊,它將阻止非組的成員的用戶將組帖子添加到該組中。drupal以編程方式禁用或刪除節點創建節點鏈接

我的模塊當前設置了必要的權限並檢測用戶是否有權限。

因此,當用戶正在查看組頁面時,我想禁用/刪除標準鏈接來創建組帖子。

回答

2

試試這種方法。

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 
    } 
} 
+0

這很有幫助。仍在努力,但我認爲這是我一直在尋找的解決方案。謝謝! – sisko

0

如果我理解正確,您不希望某些用戶創建內容類型。

所以步驟如下:

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" 
} 
+0

感謝您的非常詳細的建議 - 非常感謝。但是hook_menu會對所有組的目標用戶有影響。我需要的是通過檢測他們是否是他們當前正在訪問的組的成員來有選擇地處理目標用戶的手段 – sisko

+0

我似乎無法找到該模塊中存在太多名稱。粘貼鏈接,讓我看看他們的代碼。也許我可以建議一個替代方案 –

+0

對不起,不清楚了。我正在開發模塊。我沒有在有機組或任何插件模塊中找到所需的功能,所以我開發了一個 – sisko