Describe the bug
Trying to use fields with dot notation to access nested properties results in a few issues depending on the field types.
The problem is that the property does not get "resolved" for the configuration phase, only for retrieving the value (I think). Trying to access the field metadata doesn't work, since it's not a direct property on the entity.
To Reproduce
Try to use either a DateField or AssociationField with a nested property path (might happen for other fields to, I also ran into the same issue in a custom field trying to use the metadata).
(OPTIONAL) Additional context
DateField
AssociationField
I have created a custom PropertyTypeExtractorInterface implementation that can resolve these nested paths, because that's what I needed for my custom field. Not sure what the best solution for the bundled fields would be though, right now it's directly reading the doctrine metadata, which obviously won't work in this case.
@lukasluecke , could you provide more details on your workaround? I have an
AssociationField::new('product.game') which is generating the same issue as the one above.
If I display TextField::new('product.game.id') on the Index, it works OK though..
@Schyzophrenic I created a draft PR with my current solution just now, maybe it can help you already.
@javiereguiluz I'm open for discussions about this, but I'm pretty sure that nested properties need to be supported better one way or another.. it just leads to too much issues and confusion otherwise 馃檲
Something that might be related, and could be another approach, closer to what we had before: https://github.com/api-platform/core/pull/242/files#diff-247a81625e5c07aac3e4a9eda549fd19R123
@javiereguiluz Could you maybe give your opinion about this issue and the possible solutions?
for now you can work around it for Date fields using
Field::new('profile.date_started')
->setFormType(DateType::class)
->setFormTypeOption('widget', 'single_text')
->setTemplateName('crud/field/date')
with the template overridden to
{{ field.formattedValue.date is defined ? field.value|date('d-m-Y') : field.formattedValue }}
At least that works for me :-)
Most helpful comment
for now you can work around it for Date fields using
with the template overridden to
{{ field.formattedValue.date is defined ? field.value|date('d-m-Y') : field.formattedValue }}At least that works for me :-)