TranslationFormBundle
TranslationFormBundle copied to clipboard
Usage with unmapped field?
Hello,
I'm trying to use the a2lix translation field with a file field that is not mapped in my entity as it will not be handled by the database, but it will not work because a2lix seems to ignore the "mapped=>false" option in the field configuration.
Is there a way around this?
Thanks
I worked out that the bundle will only accept fields that are mapped to a column in an entity. I fixed it manually but it would be nice to have a real option for this.
So this basically means there is no way to manage translated files using VichUploaderBundle? This is pretty annoying and was working perfectly in 2.X.
@Dt-Sodium how did you fix it?
@Dt-Sodium Would be great if you could present your solution :)
I'm not sure anymore if this is the only thing i changed because it was a long time ago, but in if src/Form/Manipulator/DoctrineORMManipulator.php, before if line 48
if (\count($unknowsFields) > 0) {
I added
foreach ($unknowsFields as $key => $field) { if (isset($formOptions['fields'][$field]) && $formOptions['fields'][$field]['mapped']) { unset($unknowsFields[$key]); $validObjectFieldsConfig[$field] = []; } }
And add mapped = true in input configuration.
But it's a pretty dirty fix.
@webda2l Hello,
I'm also trying to add an unmapped translated field in my form and meet the same error :
-> Field(s) 'myfield' doesn't exist in App\Entity\myEntityTranslation
'myField' => [ 'label' => 'myLabel', 'mapped' => false, 'locale_options' => [ 'en' => [ 'constraints' => new NotBlank(), ], ], 'attr' => [ 'readonly' => true, 'class' => 'myClass', ], ],
Is there any workaround to this ?
Thanks
Hello,
Try the pre-release https://github.com/a2lix/AutoFormBundle/releases/tag/0.3.1 composer require a2lix/auto-form-bundle:@dev
Hello,
Thanks @webda2l for the answer, I can now display my unmapped translated field in the form. I've encountered a new problem, how to get the data from my unmapped field on form submit ?
My unmapped field is : media
$translations = $myEntity->getTranslations(); dd($translations);
Result :
"en" => App\Entity\TestTranslation {#1775 ▼
#title: "test"
#text: "test"
#media: null
#url: "http://test"
#id: null
#locale: "en"
#translatable: App\Entity\Test {#749 ▶}
}
Thanks
$form->get('translations')->get('en')->get('medias')->getData()
?
Thanks a lot it works like a charm now !
that's almost like the issue
AnnouncementTranslation.php (note: have getter and setter)
/**
* @ORM\ManyToOne(targetEntity=Media::class)
*/
private $media;
AnnouncementCrudController.php
"fields" => [
"media" => [
"field_type" => MediaType::class,
"label" => "panel.announcement.fields.media",
"mapped" => true
]
]
Field(s) 'media' doesn't exist in App\Entity\AnnouncementTranslation
i found that A2lix\AutoFormBundle\ObjectInfo\DoctrineORMInfo;
if (!$metadata->isAssociationInverseSide($assocName)) {
continue;
}
to
if (!$metadata->isAssociationInverseSide($assocName)) {
$assocsConfigs[$assocName] = [];
continue;
}
but, sometimes I have to ManyToOne field using ?
any help me ?
Hi @tamert,
The original issue seems to be fixed now — the other problem you're referencing seems to be with https://github.com/a2lix/AutoFormBundle if I'm not mistaken ?
@tamert I have the same issue, did you fix it?