Deprecation: #106405 - AbstractTypolinkBuilder->build
See forge#106405
Description
The
build method in
\TYPO3\
has been deprecated in favor of the new
\TYPO3\.
When creating custom TypolinkBuilder classes, the traditional approach was to:
- Extend
\TYPO3\CMS\ Frontend\ Typolink\ Abstract Typolink Builder - Implement the
buildmethod() - Receive dependencies via the constructor
This approach is now deprecated.
The new, recommended pattern is to implement
Typolink
directly.
The
Content property in
Abstract
has also been deprecated and will be removed in TYPO3 v15.0.
It should now be accessed via the
\Psr\
object instead.
Impact
Extension authors who have created custom TypolinkBuilder classes that extend
Abstract will see
deprecation warnings when their link builders are used.
Deprecation warnings occur when:
- A custom TypolinkBuilder class still implements the
buildmethod() - Code accesses the deprecated
$contentpropertyObject Renderer - Dependencies are passed through the constructor instead of DI
Affected installations
TYPO3 installations with extensions that:
- Create custom TypolinkBuilder classes extending
AbstractTypolink Builder - Override or extend the
buildmethod() - Access the
$contentproperty directlyObject Renderer
Migration
For end users, link generation continues to work as before using either:
Content, methodObject Renderer typolink() LinkFactory
These public APIs are not affected and do not trigger deprecations.
For extension developers, custom TypolinkBuilder implementations should now
use the new
\TYPO3\.
- Implement the new interface:
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Frontend\Typolink\AbstractTypolinkBuilder;
use TYPO3\CMS\Frontend\Typolink\LinkResultInterface;
use TYPO3\CMS\Frontend\Typolink\TypolinkBuilderInterface;
// Before (deprecated)
class MyCustomLinkBuilder extends AbstractTypolinkBuilder
{
public function build(
array &$linkDetails,
string $linkText,
string $target,
array $conf
): LinkResultInterface {
// Custom logic using $this->contentObjectRenderer
}
}
// After (recommended)
class MyCustomLinkBuilder implements TypolinkBuilderInterface
{
public function buildLink(
array $linkDetails,
array $configuration,
ServerRequestInterface $request,
string $linkText = ''
): LinkResultInterface {
$contentObjectRenderer = $request->getAttribute(
'currentContentObject'
);
// Custom logic using $contentObjectRenderer
}
}
- Use dependency injection for required services instead of accessing them through global state or constructor arguments.
- Retrieve
Contentfrom the request object rather than the deprecated property.Object Renderer
All implementations of
Typolink
are automatically registered as public services in the Dependency Injection
container, so no manual service configuration is necessary.
Extensions can maintain backward compatibility during the transition by
implementing both the old
build and the new
build methods.