Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage with unmapped field? #330

Closed
Yolo-plop opened this issue Mar 20, 2019 · 13 comments · May be fixed by #381
Closed

Usage with unmapped field? #330

Yolo-plop opened this issue Mar 20, 2019 · 13 comments · May be fixed by #381

Comments

@Yolo-plop
Copy link

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
Copy link
Author

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.

@icedevelopment
Copy link

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?

@ksiatka
Copy link

ksiatka commented Feb 11, 2020

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

@Yolo-plop
Copy link
Author

Yolo-plop commented Feb 11, 2020

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.

@camille-guerber
Copy link

@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

@webda2l
Copy link
Member

webda2l commented Jun 18, 2020

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

@camille-guerber
Copy link

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

@webda2l
Copy link
Member

webda2l commented Jun 21, 2020

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

@camille-guerber
Copy link

Thanks a lot it works like a charm now !

@tamert
Copy link

tamert commented Dec 26, 2020

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
Copy link

tamert commented Dec 26, 2020

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 ?

@tchapi
Copy link
Contributor

tchapi commented Dec 12, 2021

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 ?

@mario-fehr
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants