I have a working Extbase extension in TYPO3 V6.2, which stores Products. Now I want to learn about using Signal/Slot (Extbase variant of Hooks). I wonder why the example don't work. When I update a product in List module in the TYPO3 Backend, it saves correctly but no message appears.
File typo3conf/ext/myext/ext_localconf.php
$signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( 'TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher' );
$signalSlotDispatcher->connect(
'TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Backend',
'afterUpdateObject',
'MyVendor\\MyExt\\Service\\Signalservice',
'myAfterUpdate',
FALSE
);
File typo3conf/ext/myext/Service/Signalservice.php
namespace MyVendor\MyExt\Service;
class Signalservice implements \TYPO3\CMS\Core\SingletonInterface {
/**
* @param \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object
*/
public function myAfterUpdate(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object){
if ($object instanceof \MyVendor\MyExt\Domain\Model\Products) {
// check if we come to this point
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump('Successfully hooked - I am a slot.');
die();
}
}
}
Update 15.06.2015
A hint from Patrick Lobacher remarked, that we cannot use die() in this context. Instead, we should write a logfile. But that don't work for me either. No file was written:
File typo3conf/ext/myext/ext_localconf.php
/**
* @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher
* */
$signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager')->get('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher');
$signalSlotDispatcher->connect(
'TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Backend',
'afterUpdateObject',
function ($payload) {
$logfile = "fileadmin/test/logfile.txt";
$handle = fopen($logfile, "a+");
fwrite ($handle, 'Hi. I was written by ext_localconf.php. ' . time());
fclose ($handle);
});
Update 29.06.2015
On https://forge.typo3.org/issues/61979 Francois wrote, that "Object Manager may only be used in Extbase Context, not in ext_localconf.php".
However, the given answer even don't work for me. But perhaps it helps someone else.