Deprecation: #104684 - Fluid RenderingContext->getRequest()
See forge#104684
Description
The following methods have been marked as deprecated in TYPO3 v13 and will be removed with TYPO3 v14:
\TYPO3\
CMS\ Fluid\ Core\ Rendering\ Rendering Context->set Request () \TYPO3\
CMS\ Fluid\ Core\ Rendering\ Rendering Context->get Request ()
Impact
Calling above methods triggers a deprecation level log entry in TYPO3 v13 and will trigger a fatal PHP error with TYPO3 v14.
Affected installations
Rendering
is a relatively common call in custom
view helpers. Instances with extensions that deliver custom view helpers may
be affected. The extension scanner is not configured to find potential
places since the method names are common and would lead to too many false
positives.
Migration
Class
\TYPO3\
of the Core
extension Fluid extends class
\TYPO3Fluid\
of Fluid standalone and adds the methods
set
and
get
.
These methods are however not part of
\TYPO3Fluid\
.
Fluid standalone will not add these methods, since the view of this library should
stay free from direct PSR-7
\Server
dependencies. Having those
methods in ext:fluid
Rendering
however collides with
\Rendering
,
which is type hinted in Fluid view helper method signatures.
Fluid standalone instead added three methods to handle arbitrary additional data
in
\Rendering
:
set
,
has
and
get
. Those should be used instead.
A typical usage in a view helper before:
/** @var \TYPO3Fluid\Fluid\Core\Rendering\RenderingContext $renderingContext */
$renderingContext = $this->renderingContext;
$request = $renderingContext->getRequest();
After:
// use Psr\Http\Message\ServerRequestInterface
$request = null;
if ($renderingContext->hasAttribute(ServerRequestInterface::class)) {
$request = $renderingContext->getAttribute(ServerRequestInterface::class);
}
To stay compatible to previous TYPO3 versions while avoiding deprecation notices, the following code can be used:
// use Psr\Http\Message\ServerRequestInterface
if (
method_exists($renderingContext, 'getAttribute') &&
method_exists($renderingContext, 'hasAttribute') &&
$renderingContext->hasAttribute(ServerRequestInterface::class)
) {
$request = $renderingContext->getAttribute(ServerRequestInterface::class);
} else {
$request = $renderingContext->getRequest();
}