cmf-sandbox icon indicating copy to clipboard operation
cmf-sandbox copied to clipboard

use Alice to load fixtures

Open lsmith77 opened this issue 11 years ago • 13 comments

https://github.com/nelmio/alice

related to https://github.com/symfony-cmf/SimpleCmsBundle/pull/55

lsmith77 avatar Aug 12 '13 06:08 lsmith77

How would you handle multi lang content, I guess we need some extension to call bindTranslation?

uwej711 avatar Aug 12 '13 10:08 uwej711

i havent looked at the details yet but yeah i guess we might need something along those lines

/cc @Seldaek

lsmith77 avatar Aug 12 '13 10:08 lsmith77

one language would be handled by setting the locale field. but after that indeed we would need "something" that knows what is going on. @Seldaek phpcr-odm translated fields can be updated on the same document and with another call to bindTranslation stored in that language.

dbu avatar Aug 12 '13 10:08 dbu

Currently I use something like this in our manual fixtures:

contact:
    class: Website\ContentBundle\Document\Page
    locales:
        en:
            metaTitle: "Contact - Test"
            metaDescription: "Contact - Test"
        de:
            metaTitle: "Kontakt - Test"
            metaDescription: "Kontakt Beschreibung - Test"

which with Alice could be something like this

Website\ContentBundle\Document\Page:
    contact:
        locale:
            en:
                metaTitle: "Contact - Test"
                metaDescription: "Contact - Test"
            de:
                metaTitle: "Kontakt - Test"
                metaDescription: "Kontakt Beschreibung - Test"

uwej711 avatar Aug 12 '13 11:08 uwej711

Alice doens't support localization of an entire item at the moment. It can create two documents in two languages though and then you bind them as the two translations.. I don't know exactly how things work in the CMF nowadays but if you can articulate a bit more maybe we find a good solution. Otherwise the latest alice release has processors which allow you to modify the objects on the way to the doctrine object manager, that might also help.

Seldaek avatar Aug 12 '13 13:08 Seldaek

I did a quick research and unfortunately the different Doctrine behaviours (ORM) feature different APIs and differ again from PHPCR-ODM. I will look into the processors stuff, maybe that can help.

uwej711 avatar Aug 12 '13 13:08 uwej711

Unfortunately the processors have no knowledge of the original fixture data, so this doesn't seem to help. Maybe we can introduce an other syntax like

metaTitle:de: Titel

or

metaTitle: 
     locale: de
     value: Title

uwej711 avatar Aug 12 '13 13:08 uwej711

Can you show me in php code how it looks to populate one of those objects with multiple langs?

Seldaek avatar Aug 12 '13 13:08 Seldaek

What we need for phpcr odm in the end is something like this:

foreach ($locales as $locale => $value) {
    $page->setMetaTitle($value);
    $page->set ...   // another translated field
    $manager->bindTranslation($page, $locale);
}

It would be good to set all the fields and call bindTranslation only once per field, although it should work to repeat it for each field.

uwej711 avatar Aug 12 '13 13:08 uwej711

bindTranslation only once per document and locale - might be we would even get not nullable validation complaints otherwise.

dbu avatar Aug 12 '13 13:08 dbu

For doing this we still have the translations issue and maybe image loading although I'm not sure we have images in the fixtures ...

uwej711 avatar Aug 29 '13 08:08 uwej711

we do not have images in the fixtures yet .. but we might want to in the future.

lsmith77 avatar Aug 29 '13 08:08 lsmith77

i remove the 1.0 milestone from this task. its not critical.

dbu avatar Sep 27 '13 09:09 dbu