Project

General

Profile

Actions

Bug #93801

closed

The select Viewhelper isn't selecting the correct value from a domain model.

Added by Fabian Galinski over 3 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Fluid
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.


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Bug #92599: OptionViewHelperClosed2020-10-19

Actions
Actions

Also available in: Atom PDF