Hello
I have found a defect in sfDoctrinePlugin, in the i18n form embedding.
To start, few general :
Unlike standard embedding, i18n embeddign must have to unset duplicate fields between standard form and i18n one, like primary key and culture field.
With Doctrine, I18n table are created with the "i18n" behavior. By default, primary key is "id" field and culture field is "lang".
But, we can configure this and, per exemple, change "id" to "id_foobar" for the pk.
Now, the defect
After define a table, with the "i18n" behavior, and change "id" pk field name, embed a i18n form in parent form with the sfFormDoctrine::embedI18n() method, i always get an errors on validation of 'id' field.
This error due to sfFormDoctrine::embedI18n() method. In this one, we can read this :
$i18nObject = $this->object->Translation[$culture];
$i18n = new $class($i18nObject);
unset($i18n['id'], $i18n['lang']);
You certainly understand why this error appears : pk and culture field are hard coded.
My patch
I have right a correction for this deffect. I now give it to you for validation.
I have discover DoctrineTable? have a getIdentifier() method who return all column of pk.
So, i have modified sfFormDoctrine::embedI18n() to unset all pk fields of the translate table.
$i18nObject = $this->object->Translation[$culture];
$i18n = new $class($i18nObject);
// Unset all pks of i18n embeded form who are already defines in parent form
foreach( (array) Doctrine::getTable($i18n->getModelName())->getIdentifier() as $column )
{
unset($this[$column]);
}
Regarding to Doctrine::getTable($i18n->getModelName())->getIdentifier() (getting all fields of the pk), i have originaly found a sfDoctrineRecord::getPrimaryKey(), but i have not understand i $i18n is an instance of a child of this sfDoctrineRecord class, and the return end($identifier) tell me this method just return last field of the pk, and not the entires pk.
So, i you have a better way to this getting, i will be ok.
I join my patch to this ticket