TYPO3 Extbase 有关后端删除对象的单独代码

2023-12-13

当我的 Extbase 域对象之一从 TYPO3 后端的列表视图中删除时,我想执行一些单独的代码。

认为它可以通过覆盖来工作remove( $o )相应存储库中的方法,例如

 public function remove( $object ) {
    parent::__remove( $object );
    do_something_i_want();
}

,但我想这行不通。看起来存储库方法仅由我的扩展的操作调用/使用(例如,如果我在 FE 或 BE 插件中有一些删除操作),但当对象刚刚从后端的列表视图中删除时则不会?我(到目前为止)不使用任何 FE/BE 插件/操作 - 仅在存储文件夹的后端列表视图中使用简单的添加/编辑/删除功能。

背景:我有例如具有某种 1:n 关系的两个模型(假设singer and song),其中一个对象包含一些上传的文件(album_cover> 指向文件的 URL/uploads/myext/文件夹);使用@cascade可以很好地删除每个song属于一个singer已删除,但不会影响上传的文件(仅)song.album_cover- 随着时间的推移会导致相当多的浪费。所以我想做一些onDeletionOfSinger() { deleteAllFilesForHisSongs(); }-事物。 (同样的事情也适用于删除单个song这是album_cover-file.)

听起来很简单也很常见,但我只是没有理解它,也没有发现任何有用的东西——希望得到一些提示/指向正确的方向:-)。


列表视图在其操作过程中使用TCEmain钩子,因此您可以使用其中之一来交叉删除操作,即:processCmdmap_deleteAction

  1. 注册你的 hooks 类typo3conf/ext/your_ext/ext_tables.php

    $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass'][] = 'VENDORNAME\\YourExt\\Hooks\\ProcessCmdmap';
    
  2. 创建一个具有有效名称空间和路径的类(根据上一步)
    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
            }
        }
    } 
    
  3. 注册新钩子的类后不要忘记清除系统缓存

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

TYPO3 Extbase 有关后端删除对象的单独代码 的相关文章

  • 在 UIWebView 中显示 .rtf 文件

    我正在尝试显示为我的服务器下载的 rft 文件 我首先使用 UITextView 但我可以看到文本 但也显示了很多编码和与颜色和格式相关的奇怪字符 不管怎样 在这里搜索我发现 UITextView 无法正确显示 rtf 文本 因此 我继续尝

随机推荐