TYPO3挂钩用于任何文件上传

时间:2017-06-30 07:38:14

标签: typo3

我有TYPO3版本7.6.18,并且我想使用一个钩子,当BE或FE上的任何文件上传到网站上时,它会起作用。 有可能吗?
请帮帮我,怎么用?

1 个答案:

答案 0 :(得分:3)

我可以在这里给你两个答案:

你不会在前端找到每个文件上传的一个钩子,因为TYPO3的前端部分的上传可以通过扩展来完成,并且他们可以以任何可能的方式实现它,并且不需要提供钩子对于其他开发者。所以,sry,因为前端没有钩子。

但是后端在\TYPO3\CMS\Core\Utility\File\ExtendedFileUtility类中提供了一个钩子。它可以在扩展程序ext_localconf.php中注册,如下所示:

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_extfilefunc.php']['processData'][] = \MyVendor\MyExt\Hook\FileUtilityHook::class;

班级\MyVendor\MyExt\Hook\FileUtilityHook实施\TYPO3\CMS\Core\Utility\File\ExtendedFileUtilityProcessDataHookInterface 示例实现可能如下所示:

class FileUtilityHook implements \TYPO3\CMS\Core\Utility\File\ExtendedFileUtilityProcessDataHookInterface{
    /**
     * Post process hook that gets executed when all operations have been done
     *
     * @param string $action The action that got processed
     * @param array $cmdArr The cmdArray contains data about the file, for example $cmdArr['data'] is the file/folder to delete
     * @param array $result The results of all calls to the action handler, for example $result['delete'] = true
     * @param \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility $parentObject
     */
    public function processData_postProcessAction ($action, array $cmdArr, array $result, \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility $parentObject): void {
        if( $action === 'delete' ){
            // something got deleted
        }
    }
}

请注意,这是一个postProcess挂钩,因此在使用此挂钩时已经完成了所有操作。