Closed gonzalezlopezjm closed 2 years ago
Hi, I don't have good results on manual testing this code with my typical use case https://github.com/a2lix/Demo. It need deeper work with a bunch of phpunit tests. Feel free to work on it! In my case, I don't plan to do work on it in near future.
@gonzalezlopezjm, I just tested your fix in the Demo repo and indeed I also faced issues.
If you're interested, I found a workaround in order to display *-to-one
fields.
I added another preSetData
eventListener to my form and added manually the associated field to my TranslationType
. It's ugly but in my case it works...
Here is the sample code :
$form->getFormBuilder()
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event): void {
$this->onPreSetData($event);
})
;
private function onPreSetData(FormEvent $event): void
{
$formTranslations = $event->getForm()->get('translations');
$options = $formTranslations->getConfig()->getOptions();
foreach ($options['locales'] as $locale) {
$formTranslations->add($locale, AutoFormType::class, [
'data_class' => GalleryTranslation::class,
]);
$formTranslations->get($locale)->add('gallery', EntityType::class, [
'label' => false,
'class' => Gallery::class,
'required' => false,
]);
}
I had same problem with a OneToOne relation and I modify getFieldsConfig
in src/ObjectInfo/DoctrineORMInfo.php
.
I replace
if (!empty($fields = $metadata->getFieldNames())) {
$fieldsConfig = array_fill_keys($fields, []);
}
with
if (!empty($fields = array_diff(
array_keys($metadata->getReflectionProperties()),
$metadata->getAssociationNames()))
) {
$fieldsConfig = array_fill_keys($fields, []);
}
It's OK with all tests. I'm wondering if it's linked to your problem. [This does not work as expected]
I think this one is also solved.
I think this one is also solved.
Indeed. I close.
I want to resolve #10 with this code