Feature: #102855 - PSR-14 event for modifying resolved link result data
See forge#102855
Description
A new PSR-14 event \TYPO3\
has been introduced which serves as a more powerful replacement for the now removed
hook $GLOBALS
.
The event is being dispatched after Link
has tried to resolve a
given $urn
using defined link handlers. This means, the new event is
always dispatched, even if a handler successfully resolved the $urn
and also even in cases, TYPO3 would have thrown the
Unknown
exception.
Therefore, the new event can not only be used to resolve custom link types
but also to modify the link result data of existing link handlers and
can additionally also be used to resolve situations where no handler could be
found for a t3://
URN.
The event features the following methods:
get
- Returns the resolved link result dataResult () set
- Allows to modify the final link result dataResult () get
- Returns the link parameter (URN) to be resolvedUrn () get
- Returns the exception, which will be thrown in case no link type has been resolvedResolve Exception ()
Example
The event listener class, using the PHP attribute #
for
registration:
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\LinkHandling\Event\AfterLinkResolvedByStringRepresentationEvent;
final class AfterLinkResolvedByStringRepresentationEventListener
{
#[AsEventListener]
public function __invoke(AfterLinkResolvedByStringRepresentationEvent $event): void
{
if (str_contains($event->getUrn(), 'myhandler://123')) {
$event->setResult([
'type' => 'my-type',
]);
}
}
}
Impact
Using the new PSR-14 event, it's now possible to fully modify the resolved
link result data from Link
,
just before the result is being returned. Therefore, even the resolved data
of existing handlers can be manipulated.