2011-08-01 29 views
1

我正在寫一個Drupal 6模塊,其中我的任務是根據從註冊組合中選擇註冊的用戶在我的站點上分配特定角色由內容配置文件字段形成。 (自動分配角色模塊並不適用於我,因爲我必須使用基於角色選擇的條件字段,並且我無法獲得這兩項工作。)基於Drupal 6中的註冊字段組合設置新用戶的角色

在我的模塊中我實現了hook_user(),但我不'因爲我無法在我的&編輯或&帳戶對象中看到配置文件字段的值,所以不知道如何根據字段值做出決定。

/** 
* Implementation of hook_user(). 
*/ 
function mymodule_user($op, &$edit, &$account, $category = NULL) { 
    switch ($op) { 
    case 'isnert': 

     $rolenames = user_roles(); 

     // 6 : magical role 

     //profile_load_profile($account); // tried with and without this 

     var_dump($account); 
     //var_dump($edit); 

     if(true) { // the decision should be made here based on the combo! 
     $edit['roles'] += array('6' => $rolenames[6]); 
     } 


    break; 

PS:如果您有任何建議,如何很好地記錄消息沒有遠程調試,請包括它變成你的雁:-)

回答

1

要加載內容配置文件,您可以使用下面的給定用戶代碼:

$profile = content_profile_load('content_profile_type', $uid); 

您必須將content_profile_type替換爲您的內容配置文件的內容類型的計算機名稱。

關於你很好地記錄消息而沒有遠程調試的問題,我會建議使用devel模塊提供的dpm()函數。有關DPM()函數的詳細信息,您可以訪問http://drupal.org/node/174575

因此,加載了內容後,個人資料後,可以調用DPM()像這樣:

dpm($profile); 

這將告訴你什麼是包含的信息在Drupal主題的消息區域的$ profile變量中。

+0

謝謝,dpm()很酷! – jabal

相關問題