Attention
TYPO3 v11 has reached end-of-life as of October 31th 2024 and is no longer being maintained. Use the version switcher on the top left of this page to select documentation for a supported version of TYPO3.
Need more time before upgrading? You can purchase Extended Long Term Support (ELTS) for TYPO3 v11 here: TYPO3 ELTS.
Signals and slots (deprecated)
Warning
The extbase Signal
and the concept of using signals and slots
has been superseded by PSR-14 events
Signals and slots provide a way to extend TYPO3s Core functionality or the functionality of Extensions. Signals roughly follow the observer pattern.
Signals and slots decouple the sender (sending a signal) and the receiver(s) (called slots). Hooks depend on directly calling functions in the implementing class.
Concept of signals and slots
Whenever the sender (i.e. a Core class or the class of an extension) wants to send a signal it calls dispatch
on
the SignalSlot Dispatcher
. The sender does not have or need any information about the receivers (slots). (See
Dispatching Signals)
The receiver generates a slot by calling connect
on the SignalSlot Dispatcher
on startup. A slot always listens for
signals with name i.e. "afterExtensionUninstall" on a certain class, i.e. "InstallUtility::class". (See Using Signals
<signals-
)
The function representing the slot will be called automatically by the SignalSlot Dispatcher
whenever a signal gets
dispatched. The slot will be called with one array parameter. If several slots registered for a
signal all of them will be called. However the order in which they are being called cannot be defined or depended upon.
The slot may provide an array as return value that may or may not be used be the dispatching class depending on its implementation. In the case of several slots being connected to the signal and one or all of them have return values the return value of the previous slot will be fed into the next slot as input data. As there is no way of knowing in which order the slots will be called, several slots manipulations of the same part of the array might override each other.
As the data returned by a slot will be used as input for the next slot it must forward the entire information from the input data plus the changes being made by this slot.
Slots should never take the content of the input data array for granted, because there is no programmatic way of ensuring the returned array contains all expected data, .
Dispatching signals
Emitting a signal is a mere call of the function dispatch
on the SignalSlot Dispatcher
:
# use TYPO3\CMS\Core\Utility\GeneralUtility;
# use TYPO3\CMS\Extbase\Object\ObjectManager;
# use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
$signalSlotDispatcher = GeneralUtility::makeInstance(ObjectManager::class)->get(Dispatcher::class);
$signalArguments = [
'someData' => $someData,
'otherData' => $otherData,
'caller' => $this
];
$signalArguments = $signalSlotDispatcher->dispatch(__CLASS__, 'signalName', $signalArguments);
The data returned by the dispatch should not be taken for granted. Always perform sanity checks before using it.
Using signals
To connect a slot to a signal, use the \TYPO3\
method.
This method accepts the following arguments:
$signal
: Name of the class containing the signalClass Name $signal
: Name of the class containing the signalName $slot
: Name of the class containing the slot or the instantiated class or aClass Name Or Object \Closure
object$slot
: Name of the method to be used as a slot. IfMethod Name $slot
is aClass Name Or Object \Closure
object, this parameter is ignored and can be skipped$pass
: If set toSignal Information true
, the last argument passed to the slot will be information about the signal (Emitter
)Class Name:: signal Name
Usage example:
$signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);
$signalSlotDispatcher->connect(
\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class, // Signal class name
'afterExtensionUninstall', // Signal name
\TYPO3\CMS\Core\Core\ClassLoadingInformation::class, // Slot class name
'dumpClassLoadingInformation' // Slot name
);
In this example, we define that we want to call the method
dump
of the class
\TYPO3\
when the signal
after
of the class
\TYPO3\
is dispatched.
To find out which parameters/variables are available, open the signal's class and take a look at the dispatch call:
$this->signal
In this case, the dump
method will get the
extension key and an instance of the dispatching class as parameters.
If you are using Signals in your custom extension, you need to register the Slot in your ext_
.
Finding signals
There is no complete list of signals available, but they are easily found by
searching the TYPO3 Core or the extensions code for dispatch
.
For finding hooks, look in the Hooks Configuration.