Actions
Bug #93801
closedThe select Viewhelper isn't selecting the correct value from a domain model.
Start date:
2021-03-22
Due date:
% Done:
100%
Estimated time:
TYPO3 Version:
10
PHP Version:
Tags:
Fluid, Extbase
Complexity:
easy
Is Regression:
Sprint Focus:
Description
The type getter of this domain model will return an integer, like "1". This is not working. "0" is selected, because of an added strict check in TYPO3 10. Maybe also in TYPO3 9. The wrong code is under this. <f:form.select property="type"> <f:form.select.option value="0"> <f:translate key="frontend.user.type.I.0" extensionName="SgShop"/> </f:form.select.option> <f:form.select.option value="1"> <f:translate key="frontend.user.type.I.1" extensionName="SgShop"/> </f:form.select.option> </f:form.select>
// OptionViewHelper::isValueSelected(); /** * @param string $value * @return bool */ protected function isValueSelected(string $value): bool // The value is parsed as a string. { $selectedValue = $this->renderingContext->getViewHelperVariableContainer()->get(SelectViewHelper::class, 'selectedValue'); // This will return an integer, if used like above. if (is_array($selectedValue)) { return in_array($value, $selectedValue, true); } if ($selectedValue instanceof \Iterator) { return in_array($value, iterator_to_array($selectedValue), true); } return $value === $selectedValue; // Wrong strict check. In TYPO3 8 it was a normal check "==". }
This is a working fix for this issue, but not preferred, since the "property" option should handle it. <f:form.select property="type"> <f:form.select.option value="0" selected="{user.type} == 0}"> <f:translate key="frontend.user.type.I.0" extensionName="SgShop"/> </f:form.select.option> <f:form.select.option value="1" selected="{user.type} == 1}"> <f:translate key="frontend.user.type.I.1" extensionName="SgShop"/> </f:form.select.option> </f:form.select>
This is working as well, because the keys from the options and the value aren't compared like above. <f:form.select property="type" options="{0: 'Privat', 1: 'Geschäft'}" />
It would be great, if you guys can fix this. I think, that the strict check should just be none strict, but I didn't tested it very well, because I stick to the save workaround at this moment, until it's fixed.
Thanks in advance.
Updated by Gerrit Code Review over 3 years ago
- Status changed from New to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/68560
Updated by Gerrit Code Review over 3 years ago
Patch set 1 for branch 10.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/68592
Updated by Oliver Bartsch over 3 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset d67a7053c41b24dc0d44bfe4eebcb02473b20dfc.
Updated by Fabian Galinski over 3 years ago
That was quick. Thanks for the work! :)
Updated by Benni Mack about 3 years ago
- Related to Bug #92599: OptionViewHelper added
Actions