Reputation: 3253
I am looking to create a hook for my own extension so that one of my other extension can use the function defined in the extension.
Does anyone know how to create a new hook for creating communication between two extension?
Upvotes: 1
Views: 302
Reputation: 7016
Go for the Singal/Slot Pattern.
You can emit a signal in your code and register a slot that listens on that signal to hook into the process.
To emit a signal, inject the SignalSlotDispatcher:
/**
* @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
* @inject
*/
protected $signalSlotDispatcher;
And in your code you can emit the signal like this:
$this->signalSlotDispatcher->dispatch(
__CLASS__,
'MySignalName',
[$param1, $param2, $this]
);
In your 2nd extension you can register a slot that listens an that signal in your ext_localconf.php
:
$signalSlotDispatcher = \TYPO3\CMS\Core\Utility
\GeneralUtility::makeInstance(TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);
$signalSlotDispatcher->connect(
\Your\Class\With\The\Signal::class,
'MySignalName',
Your\Class\With\The\Slot::class,
'mySlotMethod',
false
);
Then you implement mySlotMethod
in the Slot Class and do your stuff.
EDIT: I wrote a more detailed tutorial on that Topic here.
Upvotes: 1