【问题标题】:Drupal 6: How to implement a hook?Drupal 6:如何实现挂钩?
【发布时间】:2011-02-11 17:46:47
【问题描述】:

我正在使用 Drupal 6 和 filefield module

我创建了一个简单的表单来将图像上传到服务器。我想在文件上传之前重命名文件。我注意到在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) 

【问题讨论】:

    标签: drupal drupal-6 drupal-files


    【解决方案1】:

    要调用钩子,只需将“钩子”重命名为您的模块名称,如下所示

    在你的模块某处:

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

    也仅供参考:提供了挂钩,因此您无需修改​​核心/contrib 代码即可覆盖/赞美现有功能。不建议修改 core/contrib 文件,除非您以补丁的形式提供新的通用功能:)

    【讨论】:

    • 谢谢!您不修改核心代码是完全正确的,我将尝试找到更通用的解决方案,以便使用此特定模块重命名上传的文件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-10-09
    • 1970-01-01
    • 1970-01-01
    • 2012-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多