Breaking: #106405 - TypolinkBuilder signature changes
See forge#106405
Description
To enable dependency injection for TypolinkBuilder classes, several breaking changes were introduced to the TypolinkBuilder architecture.
The following breaking changes have been made:
- The constructor of
\TYPO3\
has been removed. Extending classes can no longer rely on receivingCMS\ Frontend\ Typolink\ Abstract Typolink Builder Content
andObject Renderer Typo
through the constructor.Script Frontend Controller - All concrete TypolinkBuilder implementations now implement the new
\TYPO3\
and use dependency injection via their constructors instead of extendingCMS\ Frontend\ Typolink\ Typolink Builder Interface Abstract
with constructor arguments.Typolink Builder - The method signature of the main link building method has changed from
build
to(array &$link Details, string $link Text, string $target, array $conf) build
.Link (array $link Details, array $configuration, Server Request Interface $request, string $link Text = '')
Impact
Custom TypolinkBuilder implementations extending
Abstract
will fail with fatal errors due to the
removed constructor and changed method signatures.
Extensions that instantiate TypolinkBuilder classes directly will also fail, as the constructor signatures have fundamentally changed to use dependency injection.
Affected installations
TYPO3 installations with extensions that:
- Create custom TypolinkBuilder classes extending
Abstract
Typolink Builder - Directly instantiate TypolinkBuilder classes in PHP code
- Override or extend the
build
method of TypolinkBuilder classes()
Migration
For custom TypolinkBuilder implementations:
- Implement
\TYPO3\
CMS\ Frontend\ Typolink\ Typolink Builder Interface - Use dependency injection in the constructor for required services
- Replace the
build
method with() build
Link ()
Note: Classes implementing
Typolink
are automatically
configured as public services in the DI container - no manual configuration
is required.
Example migration:
use TYPO3\CMS\Frontend\Typolink\AbstractTypolinkBuilder;
class MyCustomLinkBuilder extends AbstractTypolinkBuilder
{
public function build(array &$linkDetails, string $linkText, string $target, array $conf): LinkResultInterface
{
// Custom link building logic
return new LinkResult('news', $linkText);
}
}
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Frontend\Typolink\TypolinkBuilderInterface;
class MyCustomLinkBuilder implements TypolinkBuilderInterface
{
public function __construct(
// Inject required dependencies
) {}
public function buildLink(array $linkDetails, array $configuration, ServerRequestInterface $request, string $linkText = ''): LinkResultInterface
{
// Custom link building logic - access ContentObjectRenderer via:
$contentObjectRenderer = $request->getAttribute('currentContentObject');
return new LinkResult('news', $linkText);
}
}
For code that instantiates TypolinkBuilder classes directly:
It is strongly recommended to use the
\TYPO3\
instead of instantiating TypolinkBuilder classes directly. The LinkFactory
handles the proper instantiation and dependency injection automatically.