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
Abstracthas been removed. Extending classes can no longer rely on receivingTypolink Builder ContentandObject Renderer \Typothrough the constructor.Script Frontend Controller - All concrete TypolinkBuilder implementations now implement the new
Typolinkand use dependency injection via their constructors instead of extendingBuilder Interface Abstractwith constructor arguments.Typolink Builder - The method signature of the main link-building method has changed from
buildto(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
AbstractTypolink Builder - Directly instantiate TypolinkBuilder classes in PHP code
- Override or extend the
buildmethod of TypolinkBuilder classes()
Migration
For custom TypolinkBuilder implementations:
- Implement
TypolinkBuilder Interface - Use dependency injection in the constructor for required services
- Replace the
buildmethod with() buildLink ()
Note: Classes implementing
Typolink are
automatically configured as public services in the dependency injection
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
Link instead of instantiating
TypolinkBuilder classes directly. The
Link handles proper
instantiation and dependency injection automatically.