2012-03-03 64 views
2

我有兩個profile2配置文件 - main和customer_profile。另外,我有一個名爲Customer的節點類型。Drupal 7以編程方式加載配置文件2

當創建新的Customer節點時,我想加載custom_profile表單。這個想法是同時創建一個節點和一個配置文件。

我知道這肯定是一個hook_form_alter解決方案,但有人可以告訴我如何在創建或編輯客戶端節點以編程方式加載配置文件。

回答

0

即使您能夠加載customer_profile表單,也需要單獨處理值,因爲它們是兩個不同的節點。

我會建議在客戶節點窗體中捕獲這些字段,然後從這些值中編程創建一個customer_profile。

如果你想獲得PROFILE2形成本身,那麼你可以使用像

module_load_include('inc', 'profile2_page', 'profile2_page'); 
$profile2 = profile2_by_uid_load($uid, 'seeker_profile'); 
$entity_form = entity_ui_get_form('profile2', $profile2, 'edit'); 

,然後添加到您要放置它的形式。

-1

我有一個類似的需要在用戶頁面創建一個自定義選項卡並在其中加載用戶profile2表單。

下面是我如何設法完成只是一個單元代碼:

MYMODULE.module https://gist.github.com/4223234

MYMODULE_profile2_MYPROFILE2TYPE.inc https://gist.github.com/4223201

希望它能幫助。

4

可以通過使用這些函數

$types = profile2_get_types(); 
profile2_load_by_user($account, $type_name = NULL) 

對於實施例加載簡檔類型和數據:

$types = profile2_get_types(); 
    if (!empty($types)) { 
     foreach ($types as $type) { 
      $profile = profile2_load_by_user($uid, $type->type); 
     } 
    } 
0

可以使用profile2_load_by_user加載完整資料數據(); PARAMS,如: -

profile2_load_by_user($account,$type_name) 
$account: The user account to load profiles for, or its uid. 
$type_name: To load a single profile, pass the type name of the profile to load 

所以這樣的代碼波紋管

$account->uid = $existingUser->uid; 
$type_name = 'user_about'; 
$profile = profile2_load_by_user($account, $type_name); 
//$profile variable have full data of profile fields 
//changing data profile2 fields 
if(isset($_POST['field_user_first_name'])&& !empty($_POST['field_user_first_name'])){ 
    $profile->field_user_first_name['und'][0]['value'] = $_POST['field_user_first_name']; 
} 
profile2_save($profile); 
0

那麼當創建一個新的配置文件,Profile2的領域是不可見的,直到手動保存完成。

自動創建PROFILE2對象,我們使用規則模塊
步驟
1)轉到Drupal的管理/配置/工作流程/規則
2)創建新的規則
3)給出的名稱和選擇反應/事件
4)動作 「保存新的用戶帳戶後」 >>添加動作>>執行定製的PHP代碼
5)將PHP代碼 $profile = profile_create(array('type' => 'profile2 type machine name', 'uid' => $account->uid)); profile2_save($profile);
6)保存>>保存更改。
這將創建新用戶時創建profile2字段。

相關問題