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 - so no template could 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:
<ap:format.replace
content="A research project of the research group"
substring="research"
replacement="teaching"
returnCount="true"
/>
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.
References
- str_replace -
the
$countparameter this returns.