AfterLinkResolvedByStringRepresentationEvent¶
New in version 13.0
This event has been introduced as a more powerful replacement for the
removed hook
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['Link']['resolveByStringRepresentation']
.
The PSR-14 event \TYPO3\CMS\Core\LinkHandling\Event\AfterLinkResolvedByStringRepresentationEvent
is being dispatched after the \TYPO3\CMS\Core\LinkHandling\LinkService
has tried to resolve a given t3://
URN using
defined link handlers.
The event can not only be used to resolve custom link types, but also to modify
the link result data of existing link handlers. Additionally, it can be used to
resolve situations where no handler could be found for a t3://
URN.
Note
The event is always dispatched, even if a handler successfully resolved
the URN and also even in cases, TYPO3 would have thrown the
\TYPO3\CMS\Core\LinkHandling\Exception\UnknownLinkHandlerException
exception.
Example¶
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\LinkHandling\EventListener;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\LinkHandling\Event\AfterLinkResolvedByStringRepresentationEvent;
#[AsEventListener(
identifier: 'my-extension/after-link-resolved-by-string-representation',
)]
final readonly class MyEventListener
{
public function __invoke(AfterLinkResolvedByStringRepresentationEvent $event): void
{
if (str_contains($event->getUrn(), 'myhandler://123')) {
$event->setResult([
'type' => 'my-type',
]);
}
}
}
New in version 13.0
The PHP attribute \TYPO3\CMS\Core\Attribute\AsEventListener
has been
introduced to tag a PHP class as an event listener. Alternatively, you can also
register an event listener via the Configuration/Services.yaml
file. Have
a look into the section Implementing an event listener in your extension.
API¶
- class \TYPO3\CMS\Core\LinkHandling\Event\ AfterLinkResolvedByStringRepresentationEvent¶
-
Listeners are able to modify the resolved link result data
- getResult ( ) ¶
-
- returntype
-
array
- setResult ( array $result) ¶
-
- param array $result
-
the result
- getUrn ( ) ¶
-
- returntype
-
string
- getResolveException ( ) ¶
-
- returntype
-
TYPO3\CMS\Core\Exception