TYPO3 TCA在将对象保存到后端后执行钩子 [英] TYPO3 TCA execute hook after object save in backend

查看:104
本文介绍了TYPO3 TCA在将对象保存到后端后执行钩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果要保存一个对象,我想操纵一些值并执行自定义函数.我通过Google搜索发现必须在 ext_localconfphp 中指定它:

I want to manipulate some values and execute a custom function if an object is saved trought the backend. I found through my google search that I have to specify this in my ext_localconfphp :

$GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass']['extkey'] = 'Vendor\\Extension\\Hook\\TCEmainHook';
$GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass']['extkey'] = 'Vendor\\Extension\\Hook\\TCEmainHook';

此外,我在扩展名/Classes/Hook/TCEmainHook.php

<?php
namespace Vendor\Extension\Hook;

class TCEmainHook {
public function processCmdmap_postProcess(
    $command, $table, $id, $value, 
    TYPO3\CMS\Core\DataHandling\DataHandler &$pObj) {
       echo '<pre>';
           var_dump($command);
       echo '<pre>';
       die();
    }
}

但是无论我尝试以下哪个选项,保存对象后我只会得到一个空的后端框架:

But no matter which of the following options I try, I just get an empty backend frame after I save an object:

$GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass']['NXS\\NxsReferenzen\\Hook\\TCEmainHook'] = 'EXT:nxs_referenzen/Classes/Hook/TCEmainHook.php';
$GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass'][''] = 'NXS\\NxsReferenzen\\Hook\\TCEmainHook';
$GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass'][''] = 'EXT:nxs_referenzen/Classes/Hook/TCEmainHook.php:\NXS\\NxsReferenzen\\Hook\\TCEmainHook';

我不明白我做错了什么.有人有什么建议吗?

I don't get what I am doing wrong. Does someone have any suggestions?

解决方案供参考: 感谢jokumer的建议,我查找了BE modul配置"中的哪些钩子以及如何加载其他钩子.我看到我的钩子看起来与其他钩子不同,所以我检查了powermail钩子的定义方式(这是我正在使用的另一个扩展),并进行了以下更改,钩子终于可以工作了:

solution for reference: Thanks to jokumer's suggestion I looked up which and how other hooks are being loaded in the BE modul 'Configuration'. I saw that my hook looked different from the others so I checked how the powermail hook has been defined (that's another extension I'm using) and with the following changes the hook is finally working:

$GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] = 'EXT:nxs_referenzen/Classes/Hook/TCEmainHook.php:NXS\\NxsReferenzen\\Hook\\TCEmainHook';
$GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass'][] = 'EXT:nxs_referenzen/Classes/Hook/TCEmainHook.php:NXS\\NxsReferenzen\\Hook\\TCEmainHook';

推荐答案

在本地配置(ext_localconf.php)中注册钩子类:

Register your hook class in local configuration (ext_localconf.php):

$GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][''] = 'NXS\\NxsReferenzen\\Hook\\TCEmainHook';
$GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass'][''] = 'NXS\\NxsReferenzen\\Hook\\TCEmainHook';

确保您的钩子类具有名称空间声明:

Ensure your hook class has namespace declaration:

<?php
namespace NXS\NxsReferenzen\Hook;

class TCEmainHook {
    public function processCmdmap_postProcess($command, $table, $id, $value, \TYPO3\CMS\Core\DataHandling\DataHandler &$pObj) {
        echo '<pre>';
        var_dump($command);
        echo '<pre>';
        die();
    }
}

这篇关于TYPO3 TCA在将对象保存到后端后执行钩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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