Bug #35894

CheckboxViewHelper and RadioViewHelper missing an existence check for formObject, and thus an exception is being thrown

Added by Sebastian Wojtowicz over 3 years ago. Updated about 3 years ago.

Status:Resolved Start date:2012-04-12
Priority:Must have Due date:
Assigned To:Sebastian Wojtowicz % Done:

100%

Category:ViewHelpers
Target version:TYPO3 Flow Base Distribution - 1.1 RC1 Estimated time:0.10 hour
Has patch:No Affected Flow version:Git master

Description

Scenario:

Controller:
    indexAction(FormObject $formObject = NULL){ ... }
Template:
    <f:form ... object="{formObject}' >
        <f:form.checkbox property="somePropertyOfFormObject" value="yes"/>
        ...
 

This scenario fails with

#1243325768: No value found for key "TYPO3\Fluid\ViewHelpers\FormViewHelper->formObject" 

The problem is that in the CheckboxViewHelper and the RadioViewHelper we call $this->getPropertyValue() which callls $formObject = $this->viewHelperVariableContainer->get('TYPO3\Fluid\ViewHelpers\FormViewHelper', 'formObject'); even though we did not check if the formObject exists, so that instead we get thrown an exception.

For example in CheckboxViewHelper.php, Line 80 before we call getPropertyValue() we only check

if ($this->isObjectAccessorMode())

while all other [InputType]ViewHelper always check (in the getValue() function):
if ($this->isObjectAccessorMode() && $this->viewHelperVariableContainer->exists('TYPO3\Fluid\ViewHelpers\FormViewHelper', 'formObject'))

So I think that in CheckboxViewHelper, Line 80 and in RadioViewHelper, Line 81 there should also be the same check for the existence of the formObject. Unless someone knows of a better place to inject that bugfix.

Associated revisions

Revision cbe93048
Added by Rens Admiraal about 3 years ago

[BUGFIX] Fix unusable checkbox/radio if formObject is NULL

When using a form object inside of a form view helper inside an index
action template and a checkbox is referring to a property $sth of
$someFormObject, the form object can be NULL with code like:

indexAction(\Some\Type $someFormObject = NULL){ ... }
&lt;f:form ... object="{someFormObject}"&gt;
&lt;f:form.checkbox property="{sth}" value="yes" checked="{sth.value} == yes"/&gt;
&lt;/f:form&gt;

Initially calling the index action makes someFormObject NULL. If the submitted
form had validation errors someFormObject is NULL, too. This possibility
was ignored in a call for the formObject from within the CheckboxViewHelper as
well as from the RadioViewHelper.

So you would get an exception telling you
No value found for key "TYPO3\Fluid\ViewHelpers\FormViewHelper->formObject"

This change fixes that bug and thus also sets the checkbox and radio
"checked" attribute properly when a validation error occurred.

Change-Id: I3d272504927fb9401e9cadc974b6b6c57ac08b6b
Fixes: #35894
Releases: 1.1, 1.2

Revision dec3b187
Added by Rens Admiraal about 3 years ago

[BUGFIX] Fix unusable checkbox/radio if formObject is NULL

When using a form object inside of a form view helper inside an index
action template and a checkbox is referring to a property $sth of
$someFormObject, the form object can be NULL with code like:

indexAction(\Some\Type $someFormObject = NULL){ ... }
&lt;f:form ... object="{someFormObject}"&gt;
&lt;f:form.checkbox property="{sth}" value="yes" checked="{sth.value} == yes"/&gt;
&lt;/f:form&gt;

Initially calling the index action makes someFormObject NULL. If the submitted
form had validation errors someFormObject is NULL, too. This possibility
was ignored in a call for the formObject from within the CheckboxViewHelper as
well as from the RadioViewHelper.

So you would get an exception telling you
No value found for key "TYPO3\Fluid\ViewHelpers\FormViewHelper->formObject"

This change fixes that bug and thus also sets the checkbox and radio
"checked" attribute properly when a validation error occurred.

Change-Id: I3d272504927fb9401e9cadc974b6b6c57ac08b6b
Fixes: #35894
Releases: 1.1, 1.2

History

#1 Updated by Karsten Dambekalns over 3 years ago

  • Target version changed from 1.0.4 to 1.0.5

#2 Updated by Sebastian Wojtowicz about 3 years ago

  • Target version changed from 1.0.5 to 1.1 beta 2
  • % Done changed from 0 to 10

The problem is that we get formObject = NULL
1. ... if we visit the index action
2. ... if the form submit fails

So upper code changes fix the exception, but at least the checkbox code doesn't seem to expect this and so the automatic checked=checked or not checked setting reflecting the last submitted form values simply does not work. So this needs to be fixed as well.

#3 Updated by Gerrit Code Review about 3 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/11637

#4 Updated by Gerrit Code Review about 3 years ago

Patch set 2 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/11637

#5 Updated by Gerrit Code Review about 3 years ago

Patch set 3 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/11637

#6 Updated by Karsten Dambekalns about 3 years ago

  • Assigned To set to Sebastian Wojtowicz

#7 Updated by Gerrit Code Review about 3 years ago

Patch set 4 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/11637

#8 Updated by Karsten Dambekalns about 3 years ago

  • Target version changed from 1.1 beta 2 to 1.1 RC1

#9 Updated by Gerrit Code Review about 3 years ago

Patch set 5 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/11637

#10 Updated by Gerrit Code Review about 3 years ago

Patch set 6 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/11637

#11 Updated by Gerrit Code Review about 3 years ago

Patch set 7 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/11637

#12 Updated by Gerrit Code Review about 3 years ago

Patch set 8 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/11637

#13 Updated by Gerrit Code Review about 3 years ago

Patch set 1 for branch FLOW3-1.1 has been pushed to the review server.
It is available at http://review.typo3.org/12164

#14 Updated by Gerrit Code Review about 3 years ago

Patch set 2 for branch FLOW3-1.1 has been pushed to the review server.
It is available at http://review.typo3.org/12164

#15 Updated by Gerrit Code Review about 3 years ago

Patch set 3 for branch FLOW3-1.1 has been pushed to the review server.
It is available at http://review.typo3.org/12164

#16 Updated by Rens Admiraal about 3 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 10 to 100

Also available in: Atom PDF