cmf-sandbox
cmf-sandbox copied to clipboard
use Alice to load fixtures
https://github.com/nelmio/alice
related to https://github.com/symfony-cmf/SimpleCmsBundle/pull/55
How would you handle multi lang content, I guess we need some extension to call bindTranslation?
i havent looked at the details yet but yeah i guess we might need something along those lines
/cc @Seldaek
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.
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"
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.
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.
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
Can you show me in php code how it looks to populate one of those objects with multiple langs?
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.
bindTranslation only once per document and locale - might be we would even get not nullable validation complaints otherwise.
For doing this we still have the translations issue and maybe image loading although I'm not sure we have images in the fixtures ...
we do not have images in the fixtures yet .. but we might want to in the future.
i remove the 1.0 milestone from this task. its not critical.