簡體   English   中英

如何判斷用戶是否更新了 Drupal 7 中的配置文件字段

[英]How to tell if a user has updated a profile field in Drupal 7

我正在嘗試確定在 drupal 7 中如何以編程方式判斷用戶是否在過去 24 小時內更新了他們的個人資料中的自定義字段,但是查看表格我似乎找不到任何包含該信息的字段想法?? 本質上,我需要在每晚運行一次的批處理作業中提取這些信息,並根據 drupal 中的信息更新其他系統。 如果有人能想到更好的方法來做到這一點,將不勝感激。 感謝您的任何幫助,您可以提供

好的,我不知道它是否有效,請嘗試以下步驟

1-首先你應該告訴 drupal ....當用戶編輯個人資料頁面時做一些事情......(不管是什么......向數據庫中插入一些東西......檢索一些東西......等等)

/**
* Implementation of hook_form_alter
*/
function newcontent_form_alter(&$form, &$form_state, $form_id){
if($form_id == 'user_profile_form'){
    $form['#submit'][]  = '_do_something_when_user_save_profile';   
}    
}   


/**
* do something when user save profile
*/
function _do_something_when_user_save_profile($form,$form_state){
// do something
}   

現在我想我們需要做一些查詢......首先我們需要創建2個表http://api.drupal.org/api/drupal/modules--system--system.Z8A5DA52ED126447D359E70C057AschemaA8AZ.php/function/hook (此 url 將幫助您創建架構)

  • 第一個表將包含你想要跟蹤的字段的當前值,所以我認為這個表應該有以下字段(主鍵、用戶 ID、字段名稱、字段值)

  • 第二個表將包含用戶最后一次更新操作的日期,我認為這些字段將如下所示(主鍵、用戶 ID、字段名稱、日期)

現在讓我們返回表單提交 function

/**
* do something when user save profile
*/
function _do_something_when_user_save_profile($form,$form_state){
   // now i can check in the first table to see
       // is the current submitted value for this field = the value in the table
       // if its = the table value then the user didn't change any thing now i dont 
       // need to update the second table
       // if the current submitted value != the value in the table then its mean
       // that the user have updated this field ... 
       // now i should insert new value to the second 
       // table with the current date time and the current field value
}   

我希望你能理解我,並為我糟糕的英語感到抱歉

maged adel 提供了合理的解決方案,但是還有另一種方法:您可以為此目的使用hook_user_update 上面提供的解決方案更好,原因有兩個:1)您同時擁有 $edit - 輸入的值和 $account - 用戶帳戶值,因此您可以比較並了解正在更新的字段(如果您沒有 1 個特定字段去檢查)。 2) 只需 1 個鈎子即可實現。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM