Skip to content

Commit

Permalink
FIX: InvalidArgumentForHashGenerationException
Browse files Browse the repository at this point in the history
This occurs on failed serverside validations: The form field "tx_powermail_pi1[field][mycheckboxes][][]" is invalid. Reason: "[]" used not as last argument, but somewhere in the middle (like foo[][bar]).

Related: TYPO3-Headless#34
  • Loading branch information
kitzberger committed Aug 2, 2024
1 parent 85bcf15 commit 193e328
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 46 deletions.
34 changes: 0 additions & 34 deletions Classes/ViewHelpers/Form/RegisterFieldViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,10 @@
*/
class RegisterFieldViewHelper extends AbstractFormFieldViewHelper
{
public function initializeArguments(): void
{
$this->registerArgument('name', 'string', 'Name of input tag');
$this->registerArgument('value', 'mixed', 'Value of input tag');
$this->registerArgument(
'property',
'string',
'Name of Object Property. If used in conjunction with <f:form object="...">, "name" and "value" properties will be ignored.'
);
$this->registerArgument('additionalAttributes', 'array', 'Additional tag attributes. They will be added directly to the resulting HTML tag.', false);
$this->registerArgument('checked', 'bool', 'Specifies that the input element should be preselected');
$this->registerArgument('multiple', 'bool', 'Specifies whether this checkbox belongs to a multivalue (is part of a checkbox group)', false, false);
}

public function render(): string
{
$nameAttribute = $this->getName();

$checked = $this->arguments['checked'];
$multiple = $this->arguments['multiple'];

$propertyValue = null;
if ($this->hasMappingErrorOccurred()) {
$propertyValue = $this->getLastSubmittedFormData();
}
if ($checked === null && $propertyValue === null) {
$propertyValue = $this->getPropertyValue();
}

if ($propertyValue instanceof \Traversable) {
$propertyValue = iterator_to_array($propertyValue);
}
if (is_array($propertyValue)) {
$nameAttribute .= '[]';
} elseif ($multiple === true) {
$nameAttribute .= '[]';
}

$this->registerFieldNameForFormTokenGeneration($nameAttribute);

return '';
Expand Down
4 changes: 1 addition & 3 deletions Resources/Private/Partials/Form/Field/Check.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{namespace vh=In2code\Powermail\ViewHelpers}
<f:spaceless>
<headlesspowermail:form.registerField property="{field.marker}."
value="{setting.value}"
checked="{vh:misc.prefillMultiField(field:field, mail:mail, cycle:iteration.cycle)}"/>
<headlesspowermail:form.registerField property="{field.marker}." />
<f:format.raw>
<f:format.json value="{
field: {
Expand Down
4 changes: 1 addition & 3 deletions Resources/Private/Partials/Form/Field/Country.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{namespace vh=In2code\Powermail\ViewHelpers}
<f:spaceless>
<f:variable name="fieldMarker" value="{field.marker}{f:if(condition:field.multiselect,then:'.')}" />
<headlesspowermail:form.registerField property="{fieldMarker}"
value="{setting.value}"
checked="{vh:misc.prefillMultiField(field:field, mail:mail, cycle:index.cycle)}"/>
<headlesspowermail:form.registerField property="{fieldMarker}" />
<f:format.raw>
<f:format.json value="{
field: {
Expand Down
4 changes: 1 addition & 3 deletions Resources/Private/Partials/Form/Field/Radio.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{namespace vh=In2code\Powermail\ViewHelpers}
<f:spaceless>
<headlesspowermail:form.registerField property="{field.marker}."
value="{setting.value}"
checked="{vh:misc.prefillMultiField(field:field, mail:mail, cycle:iteration.cycle)}"/>
<headlesspowermail:form.registerField property="{field.marker}." />
<f:format.raw>
<f:format.json value="{
field: {
Expand Down
4 changes: 1 addition & 3 deletions Resources/Private/Partials/Form/Field/Select.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{namespace vh=In2code\Powermail\ViewHelpers}
<f:spaceless>
<f:variable name="fieldMarker" value="{field.marker}{f:if(condition:field.multiselect,then:'.')}" />
<headlesspowermail:form.registerField property="{fieldMarker}"
value="{setting.value}"
checked="{vh:misc.prefillMultiField(field:field, mail:mail, cycle:iteration.cycle)}"/>
<headlesspowermail:form.registerField property="{fieldMarker}" />
<f:format.raw>
<f:format.json value="{
field: {
Expand Down

0 comments on commit 193e328

Please sign in to comment.