[TYPO3-mvc] Re: desperation with f:form.checkbox
Philipp
philippwrann at gmx.at
Fri May 3 11:31:51 CEST 2013
Okay i found the problem.... and yes - in my opinnion - it is a bug:
If a form object is a array, the ViewHelper tries to get the property this way
$formObject[$propertyName]
and not using return \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($formObject, $propertyName);
So, whats the solution?
Can i use an Object of Type \StdClass Here, would the ObjectAccess Utility then understand the path? I dont really think so, because there is no Reflection of StdClass. So do i have to create a model for this? Thats not what i want to do because this is a basic routine, that should be extended by other controllers, i cant handle one model and therefore wanted to use a simple array.
There has to be made an addition in the ViewHelper
AbstractFormFieldViewHelper
On line 183 a string containing "." should be exploded
something like this does the job:
/**
* Get the current property of the object bound to this form.
*
* @return mixed Value
*/
protected function getPropertyValue() {
$formObject = $this->viewHelperVariableContainer->get('TYPO3\\CMS\\Fluid\\ViewHelpers\\FormViewHelper', 'formObject');
$propertyName = $this->arguments['property'];
if (is_array($formObject)) {
if (strpos($propertyName,'.')!==FALSE) {
$parts = explode('.',$propertyName);
$return = $formObject;
while (sizeof($parts)>0) {
$return = $return[array_shift($parts)];
if ($return===NULL) return NULL;
}
return $return;
}
return isset($formObject: NULL;
}
return \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($formObject, $propertyName);
}
More information about the TYPO3-project-typo3v4mvc
mailing list