Example code for Custom ViewHelper registers an argument but does not use it
In section "With render()
This code snippets registers an argument and never uses it. (It uses the content of the html tag instead which is the point of this section. However, I think the argument statement should be removed or commented out with a comment. Or it should be solved like in the next snippet, where both is supported: passing the email as argument and as content:
$emailAddress = $this->arguments['emailAddress'] ?? $this->renderChildren();
IMHO I don't think it makes sense to have 2 different solutions for how the argument vs. content is handled.
Code from docs (inserted comments with >>> by me): https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/Fluid/DevelopCustomViewhelper.html#with-renderstatic
public function initializeArguments()
{
>>> this argument emailAddress is not used
$this->registerArgument('emailAddress', 'string', 'The email address to resolve the gravatar for');
<<<<
}
public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
>>> in the other snippet we have something like: $emailAddress = $this->arguments['emailAddress'] ?? $this->renderChildren();
$emailAddress = $renderChildrenClosure();
<<<
return '<img src="http://www.gravatar.com/avatar/' .
md5($emailAddress) .
'" />';
}
I think the documentation should cover both options.
It's not the decision of the documentation team if both or only one option is included in a ViewHelper, but both options should be documented.
The preference might also depend on the kind how the ViewHelper is used (inline or as xml-tag). So having both options might perhaps be useful.