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
render
Static - Rename method to
render
, remove the arguments, remove() static
declaration -
Within that method:
- Replace
$arguments
with$this->arguments
- Replace
$rendering
withContext $this->rendering
Context - Replace
$render
withChildren Closure () $this->render
Children () - Replace remaining
$render
usages with proper closure handling, likeChildren Closure $this->render
.Children (...)
- Replace
- Replace
resolve
withContent Argument Name ( get
Content 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
render
parameters)Static -
If you previously called ViewHelper's
render
methods in other places, you may utilize something like:Static $this->renderingContext->getViewHelperInvoker()->invoke( MyViewHelper::class, $arguments, $this->renderingContext, $this->renderChildren(...), );
Copied!