Feature: The replace view helper can return the number of edits
Description
\FGTCLB\ counted its
replacements and returned the count instead of the replaced content when a
return argument was set:
if ($this->arguments['returnCount'] ?? false) {
return $count;
}
That argument was never registered, and Fluid rejects an argument a view helper does not declare while it parses the template. No template could therefore reach the branch:
Undeclared arguments passed to ViewHelper
FGTCLB\AcademicProjects\ViewHelpers\Format\ReplaceViewHelper: returnCount.
Valid arguments are: content, substring, replacement, caseSensitive
return is a registered boolean argument now, defaulting to
false
:
<html xmlns:ap="http://typo3.org/ns/FGTCLB/AcademicProjects/ViewHelpers"
data-namespace-typo3-fluid="true">
<ap:format.replace
content="A research project of the research group"
substring="research"
replacement="teaching"
returnCount="true"
/>
</html>
renders 2.
Impact
Nothing changes for a template that does not pass the argument. The default
returns the replaced content, as before. A template that passed
return used to raise the parse error above and renders the count
now.
The count is the one
str_ and
str_ report, so
it counts occurrences rather than distinct substrings, and it is 0 for a
substring that does not occur.
Affected Installations
Installations with templates that use the view helper. No action is required.
References
- str_replace,
the
$countparameter this returns.