TYPO3 TCA execute hook after object save in backend

旧街凉风 提交于 2019-12-01 07:12:02

问题


I want to manipulate some values and execute a custom function if an object is saved trought the backend. I found trought 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';

additionaly i created the following class at my extension /Classes/Hook/TCEmainHook.php

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 safe 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 dont get what I am doing wrong. Does someone have an suggestions?

solution for reference: Thanks to jokumer suggestion I looked up wich and how other hooks are beeing loaded in the BE modul 'Configuration'. I saw that my hook looked different as the others so I checked how the powermail hook has been defined (thats another extension im 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';

回答1:


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();
    }
}


来源:https://stackoverflow.com/questions/42603955/typo3-tca-execute-hook-after-object-save-in-backend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!