2010-01-20 103 views
2

我有一個cck FileField附加到內容類型。當我從節點中刪除文件時,我想刪除對該文件的引用,但將該文件保留在服務器上。原因是因爲我們在網站上使用IMCE,其他項目可能會引用圖像。你知道這是不是可能嗎?Drupal FileField從節點中刪除文件,但離開服務器

回答

2

從FileField_delete看代碼在這裏:

function field_file_delete($file, $force = FALSE) { 
    $file = (object)$file; 
    // If any module returns a value from the reference hook, the 
    // file will not be deleted from Drupal, but file_delete will 
    // return a populated array that tests as TRUE. 
    if (!$force && $references = module_invoke_all('file_references', $file)) { 
    $references = array_filter($references); // only keep positive values 
    if (!empty($references)) { 
     return $references; 
    } 
    } 

它看起來像hook_file_references可能會幫你的忙。但是我看不到使用這個鉤子的許多模塊(filefield除外)。

您可以編寫自己的模塊來跟蹤特定字段並實現您自己的hook_file_references。例如,您可以跟蹤特定的cck值,並在調用掛接時查詢它們。

+0

如果您使用類似http://drupal.org/project/filefield_sources的文件,並且該文件與其他節點相關聯,那麼文件將不會被刪除,直到刪除引用文件的最後一個節點。 – jhedstrom 2010-01-20 18:49:19

0

同時檢查在保存時是否沒有創建節點的新版本。在這種情況下,文件不會從文件系統中刪除,因爲它將保持連接到原始修訂版本。