-
Notifications
You must be signed in to change notification settings - Fork 9
Description
If one uses an input of type multicheckbox in the form definition, which contains more than one entry, and a frontend-user actually selects any of those checkboxes, an error will occurr in the EmailFinisher, letting the whole form finisher workflow fail.
Reason: The value of a multicheckbox field out of the FormFramework is an array, but the original EmailFinisher class can only deal with string-like values. The array value causes an exception to be risen, breaking the form finisher workflow.
Suggestion to fix this: Overwrite method TYPO3\CMS\Form\Domain\Finisher\AbstractFinisher::substituteRuntimeReferences and add support for array values.
This would be the code to add in class Kitzberger\FormMailtext\Domain\Finishers\EmailFinisher - note the is_array check at the very bottom:
protected function substituteRuntimeReferences($needle, FormRuntime $formRuntime) {
// neither array nor string, directly return
if(!is_array($needle) && !is_string($needle)) {
return $needle;
}
// resolve (recursively) all array items
if(is_array($needle)) {
$substitutedNeedle = [];
foreach($needle as $key => $item) {
$key = $this->substituteRuntimeReferences($key, $formRuntime);
$item = $this->substituteRuntimeReferences($item, $formRuntime);
$substitutedNeedle[$key] = $item;
}
return $substitutedNeedle;
}
// substitute one(!) variable in string which either could result
// again in a string or an array representing multiple values
if(preg_match('/^{([^}]+)}$/', $needle, $matches)) {
return $this->resolveRuntimeReference(
$matches[1],
$formRuntime
);
}
return preg_replace_callback(
'/{([^}]+)}/',
function($matches) use ($formRuntime) {
$value = $this->resolveRuntimeReference(
$matches[1],
$formRuntime
);
// substitute each match by returning the resolved value
if(is_array($value)) {
return implode(' / ', $value);
}
return $value;
},
$needle
);
}