且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

TYPO3 Extbase删除对象的单个代码

更新时间:2023-11-26 15:58:46

列表视图在操作过程中使用TCEmain挂钩,因此您可以使用其中的一个与删除动作相交,即:

List view uses TCEmain hooks during its operations, so you can use one of them to intersect delete action, i.e.: processCmdmap_deleteAction

  1. typo3conf/ext/your_ext/ext_tables.php

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass'][] = 'VENDORNAME\\YourExt\\Hooks\\ProcessCmdmap';

  • 创建具有有效名称空间和路径的类(根据上一步)
    文件:typo3conf/ext/your_ext/Classes/Hooks/ProcessCmdmap.php

  • Create a class with valid namespace and path (according to previous step)
    file: typo3conf/ext/your_ext/Classes/Hooks/ProcessCmdmap.php

    <?php
    namespace VENDORNAME\YourExt\Hooks;
    
    class ProcessCmdmap {
       /**
        * hook that is called when an element shall get deleted
        *
        * @param string $table the table of the record
        * @param integer $id the ID of the record
        * @param array $record The accordant database record
        * @param boolean $recordWasDeleted can be set so that other hooks or
        * @param DataHandler $tcemainObj reference to the main tcemain object
        * @return   void
        */
        function processCmdmap_postProcess($command, $table, $id, $value, $dataHandler) {
            if ($command == 'delete' && $table == 'tx_yourext_domain_model_something') {
                // Perform something before real delete
                // You don't need to delete the record here it will be deleted by CMD after the hook
            }
        }
    } 
    

  • 注册新的钩子类后不要忘记清除系统缓存

  • Don't forget to clear system cache after registering new hook's class