0

i have entity languages with format

id; name

en; English

pl; Polish

etc...

And I have some Entity translations, that in one column has an associative array: {pl: "Some txt in PL", en: "Some txt in EN",...}

Everything is almost perfect, but i don't know how to create an form for editing such a thing :D I tried almost everything.

Translation.orm.yml:

...
    id:
        id:
            type: integer
            generator: { strategy: AUTO }
    fields:
        name:
            type: string
            length: 255
            unique: true
        value:
            type: array
...

1 Answer 1

1

For new Entity you must prepare your array in Controller ( before creating form). Something like that:

$value = array('en' => 'here en', 'pl' => 'here pl');
$translation->setValue($value);
$form = $this->createForm(new TranslationType()...

In Your FormType:

 $builder->add('value', 'collection', array(
        'type' => 'text',
        'options' => array(
            'required'  => true,
        ),
     )
 );

That's all. If you have {{ form_rest(form) }} in your twig, you'll see two additional fields for translations in your form and it will be work. Additional information about collection field type is here

Sign up to request clarification or add additional context in comments.

2 Comments

Okey, that seems fine, but i want to have possibility to edit content in this 'array', and your solution give me only possibility to choose options?
Each element of array will be editable in your form without any additional work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.