TranslationFormBundle icon indicating copy to clipboard operation
TranslationFormBundle copied to clipboard

Usage with unmapped field?

Open Yolo-plop opened this issue 5 years ago • 13 comments

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

Yolo-plop avatar Mar 20 '19 13:03 Yolo-plop

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.

Yolo-plop avatar Mar 25 '19 13:03 Yolo-plop

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?

icedevelopment avatar Apr 26 '19 14:04 icedevelopment

@Dt-Sodium Would be great if you could present your solution :)

ksiatka avatar Feb 11 '20 08:02 ksiatka

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.

Yolo-plop avatar Feb 11 '20 08:02 Yolo-plop

@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

camille-guerber avatar Jun 18 '20 14:06 camille-guerber

Hello, Try the pre-release https://github.com/a2lix/AutoFormBundle/releases/tag/0.3.1 composer require a2lix/auto-form-bundle:@dev

webda2l avatar Jun 18 '20 19:06 webda2l

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

camille-guerber avatar Jun 19 '20 09:06 camille-guerber

$form->get('translations')->get('en')->get('medias')->getData() ?

webda2l avatar Jun 21 '20 17:06 webda2l

Thanks a lot it works like a charm now !

camille-guerber avatar Jun 22 '20 08:06 camille-guerber

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

tamert avatar Dec 26 '20 18:12 tamert

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 ?

tamert avatar Dec 26 '20 22:12 tamert

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 ?

tchapi avatar Dec 12 '21 19:12 tchapi

@tamert I have the same issue, did you fix it?

mario-fehr avatar Jun 08 '22 13:06 mario-fehr