[TYPO3-dev] Checkbox-viewhelper doesn't handle ObjectStorages correctly regarding object-creation
Michael Bakonyi
kontakt at mb-neuemedien.de
Sun Oct 5 12:20:39 CEST 2014
Hi everone,
Use case: Via a fluid form you want to create an object with an
associated property of type ObjectStorage (e.g. an 1:n-relation). The
records of the property shall be represented via checkboxes.
The problem is, that the checkbox-viewhelper only rendeders the
name-attribute correclty like this
"tx_myExt_pi1[myObject][myProperty][]" (with the extended
"[]"-characters at the end) when there's a form-object already. So if
you want to edit your object, everything's fine, as the object is
already existant/persisted. In case you don't have a form-object as you
want to create a new object with the form the viewhelper doesn't
generate an array-value within the name-attribute. This results in not
persisted form-values.
The code-problem in detail:
The checkbox-viewhelper tries to get the property-value via
getPropertyValue() which comes from AbstractFormFieldViewHelper.php.
Based on the returned value of this function the decision is taken to
extend the regular value of the name-attribute with the needed
"[]"-characters or not. In the function getPropertyValue() there's a
check for the existance for a form-object (see also
https://forge.typo3.org/issues/35894) and if no such object is existing
the function returns nothing and thus no "[]"-characters are added.
I could provide a patch with which a new attribute "multiple" is
registered for the checkbox-viewhelper. So even if the propertyValue
returns nothing the characters get added, if multiple="1" is set for the
checkbox-viewhelper.
But I don't think this is a clean approach and would like to hear some
thoughts of you, who are more familiar with all the fluid-generation
including sideffects regarding changes within the core-code.
Cheers,
Michael
More information about the TYPO3-dev
mailing list