TYPO3 Extbase删除对象的单个代码 [英] TYPO3 Extbase individual code on backend-deletion of an object

查看:52
本文介绍了TYPO3 Extbase删除对象的单个代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to execute some individual code when one of my Extbase domain objects is deleted from the list view in TYPO3 backend.

认为通过覆盖相应存储库中的remove( $o )方法(如

Thought that it could / would work by overwriting the remove( $o ) method in the according repository like

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

,但是我猜那行不通.看起来存储库方法仅由我的扩展程序的动作调用/使用(例如,如果我在FE或BE插件中具有某些delete-action),但是当仅从后端的列表视图中删除对象时却不调用/使用该方法? (到目前为止)我不使用任何FE/BE插件/-actions-仅在存储文件夹的后端列表视图中使用简单的添加/编辑/删除功能.

, but that won't work I guess. Looks like the repository-methods are only called / used by actions of my extension (e.g. if I had some delete-action in a FE- or BE-plugin) but not when the object is just deleted from list view in the backend? I don't use (up to now) any FE/BE-plugin / -actions - only the simple add/edit/delete functions in the backends list view of my storage folder.

背景:例如两个具有1:n关系的模型(假设singersong),其中一个对象包含一些上载的文件(album_cover>指向/uploads/myext/文件夹中文件的URL);使用@cascade可以很好地删除属于已删除的singer的每个song,但不会(仅)触摸song.album_cover上载的文件-随着时间的流逝,会产生相当多的浪费.所以我很想做一些onDeletionOfSinger() { deleteAllFilesForHisSongs(); }事情. (同样的情况也适用于删除单个song且它是album_cover文件的情况.)

Background: I have e.g. two models with some 1:n relation (let's say singer and song), where one object includes some uploaded file (album_cover > pointing to the file's URL in /uploads/myext/ folder); using @cascade works fine for deleting every song belonging to a singer that is deleted, but it won't touch the file uploaded (only) for song.album_cover - leading to quite some waste over time. So I would love to do some sort of onDeletionOfSinger() { deleteAllFilesForHisSongs(); }-thing. (Same thing would apply on deletion of let's say a single song and it's album_cover-file.)

听起来很容易&常见,但是我只是没有落后,却发现没有任何用处-会喜欢一些提示/指向正确的方向:-).

Sounds quite easy & common, but I just don't get behind it and found nothing useful - would love some hint / pointing to the right direction :-).

推荐答案

列表视图在操作过程中使用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

    这篇关于TYPO3 Extbase删除对象的单个代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆