BeforeTypoLinkEncodedEvent

New in version 13.0: This event has been introduced to avoid extending/XCLASSing the \TYPO3\CMS\Core\LinkHandling\TypoLinkCodecService. Extending/XCLASSing no longer works since TYPO3 v13, as the TypoLinkCodecService has been declared as final and readonly.

The PSR-14 event \TYPO3\CMS\Core\LinkHandling\Event\BeforeTypoLinkEncodedEvent allows developers to fully manipulate the encoding of TypoLinks.

A common use case for extensions is to extend the TypoLink parts to allow editors adding additional information, for example, custom attributes can be inserted to the link markup.

Example

EXT:my_extension/Classes/LinkHandling/EventListener/MyEventListener.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\LinkHandling\EventListener;

use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\LinkHandling\Event\BeforeTypoLinkEncodedEvent;

#[AsEventListener(
    identifier: 'my-extension/before-typolink-encoded'
)]
final class MyEventListener
{
    public function __invoke(BeforeTypoLinkEncodedEvent $event): void
    {
        $typoLinkParameters = $event->getParameters();

        if (str_contains($typoLinkParameters['class'] ?? '', 'foo')) {
            $typoLinkParameters['class'] .= ' bar';
            $event->setParameters($typoLinkParameters);
        }
    }
}

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\BeforeTypoLinkEncodedEvent

Listeners are able to modify the to be encoded TypoLink parameters

getParameters()
Return type

array

setParameters(array $parameters)
Parameters
  • $parameters (array) -- the parameters

getTypoLinkParts()
Return type

array

getDelimiter()
Return type

string

getEmptyValueSymbol()
Return type

string