Deprecation: #104789 - renderStatic() for Fluid ViewHelpers
See forge#104789
Description
The usage of
render for Fluid ViewHelpers has been deprecated.
Also, Fluid standalone traits
\TYPO3Fluid\
and
\TYPO3Fluid\
have been marked as deprecated.
Impact
Using one of the mentioned traits or
render in ViewHelpers
logs a deprecation level error message in Fluid standalone v4.
render
will no longer be called in Fluid standalone v5.
render and both
traits continue to work without deprecation level error message in
Fluid standalone v2.
Affected installations
Instances with custom ViewHelpers using any variant of
render are affected.
Migration
ViewHelpers should always use
render as their primary rendering method.
ViewHelpers using just
render without any trait or with the trait
\Compile
can be migrated by converting the static rendering method to a non-static method:
Before:
class MyViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string
{
return $renderChildrenClosure();
}
}
After:
class MyViewHelper extends AbstractViewHelper
{
public function render(): string
{
return $this->renderChildren();
}
}
ViewHelpers using
\TYPO3Fluid\
can use the new contentArgumentName feature added with Fluid v2.15:
Before:
class MyViewHelper extends AbstractViewHelper
{
use CompileWithContentArgumentAndRenderStatic;
public function initializeArguments(): void
{
$this->registerArgument('value', 'string', 'a value');
}
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string
{
return $renderChildrenClosure();
}
public function resolveContentArgumentName(): string
{
return 'value';
}
}
After:
class MyViewHelper extends AbstractViewHelper
{
public function initializeArguments(): void
{
$this->registerArgument('value', 'string', 'a value');
}
public function render(): string
{
return $this->renderChildren();
}
public function getContentArgumentName(): string
{
return 'value';
}
}
Here is a basic recipe to perform this migration, preferably utilizing
statical code analysis/replacement tools on your *View
files:
- Find definitions of
renderStatic - Rename method to
render, remove the arguments, remove() staticdeclaration -
Within that method:
- Replace
$argumentswith$this->arguments - Replace
$renderingwithContext $this->renderingContext - Replace
$renderwithChildren Closure () $this->renderChildren () - Replace remaining
$renderusages with proper closure handling, likeChildren Closure $this->render.Children (...)
- Replace
- Replace
resolvewithContent Argument Name ( getContent Argument Name ( -
Remove the mentioned definitions:
use TYPO3Fluid\Fluid\ Core\ Rendering\ Rendering Context Interface; use TYPO3Fluid\Fluid\ Core\ View Helper\ Traits\ Compile With Render Static; use TYPO3Fluid\Fluid\ Core\ View Helper\ Traits\ Compile With Content Argument And Render Static; use Compile(class trait)With Render Static; use Compile(class trait)With Content Argument And Render Static;
- (Optionally remove custom phpdoc annotations to the
renderparameters)Static -
If you previously called ViewHelper's
rendermethods in other places, you may utilize something like:Static $this->renderingContext->getViewHelperInvoker()->invoke( MyViewHelper::class, $arguments, $this->renderingContext, $this->renderChildren(...), );Copied!