2011-02-11 35 views
0

我正在使用Drupal 6和filefield moduleDrupal 6:如何實現一個鉤子?

我創建了一個簡單的表單將圖像上傳到服務器。我想在上傳之前重命名文件。我注意到,在field_file_save_upload函數中,提到了實現hook_file_insert允許您操作文件的屬性。我不知道如何實現這個鉤子。我應該在新模塊中實現它,還是直接在field_file.inc文件中實現它?它應該被命名爲field_file_insert

的文檔指出以下幾點:

/** 
* Save a file upload to a new location. 
* The source file is validated as a proper upload and handled as such. By 
* implementing hook_file($op = 'insert'), modules are able to act on the file 
* upload and to add their own properties to the file. 
... 
*/ 
function field_file_save_upload($source, $validators = array(), $dest = FALSE) 

回答

2

要調用一個鉤子只是「hook_」重命名爲您的模塊的名稱,比如你的模塊中,從而

地方:

function MYMODULENAME_file_insert(.....){ 
    // Do things 
} 

也只是供參考:提供了鉤子,因此您不必修改核心/ contrib代碼來覆蓋/補充現有功能。不建議修改核心/ contrib文件,除了提供新的通用功能,您可以以補丁的形式回饋:)

+0

謝謝!關於不修改核心代碼是完全正確的,我會嘗試找到更通用的解決方案,以便使用此特定模塊重命名上傳的文件。 – jdecuyper 2011-02-15 19:18:40

相關問題