Checkbox viewhelper should correctly compare non-entity objects in collections #1671
Open
Description
Currently the checkbox viewhelper supports comparing against a collection property in order to do a "contains" check for the value. This however always assumes entities and tries to compare against the persistenceIdentifier, which fails for non-entity objects like e.g. Roles
or other value objects.
<f:section name="Content">
<f:form method="post" action="updateRoles" objectName="account" object="{account}" arguments="{account: account}">
<label>Roles</label>
<f:for each="{roles}" as="role" iteration="iterator">
<label>
<f:form.checkbox property="roles" value="{role}" multiple="true" /> {role.name}
</label>
</f:for>
<f:form.submit class="btn btn-primary" value="Update" />
</f:form>
</f:section>
This template currently behaves wrong and will not check the roles assigned to the account.
See c4b15e8#diff-c710aa37625a231b5c692f161d74fd4f
The // assume an entity
part would probably need to be changed to something similar to:
$valueIdentifier = $this->persistenceManager->getIdentifierByObject($value);
if ($valueIdentifier !== null) {
$checked = $valueAttribute === $valueIdentifier;
} else {
$checked = $valueAttribute == $value;
}