class MyArticleForm extends ArticleForm { public function configure() { parent::configure(); $this->embedI18n(array('en', 'fr')); $authorForm = new AuthorForm($this->object->Author); unset($authorForm['id']); $this->embedForm('Author', $authorForm); unset($this['author_id']); } } $article = new Article(); $articleForm = new MyArticleForm($article); $data = array('is_on_homepage' => 1, 'Author' => array('name' => 'i18n author test', 'type' => null), 'en' => array('title' => 'english title', 'body' => 'english body'), 'fr' => array('title' => 'french title', 'body' => 'french body'), 'created_at' => time(), 'updated_at' => time()); $articleForm->bind($data); $t->is($articleForm->isValid(), true); $data = $articleForm->getValues(); $values = array('is_on_homepage' => true, 'Author' => array('name' => 'i18n author test', 'type' => null), 'en' => array('title' => 'english title', 'body' => 'english body', 'test_column' => '', 'slug' => ''), 'fr' => array('title' => 'french title', 'body' => 'french body', 'test_column' => '', 'slug' => ''), 'id' => null, 'created_at' => $data['created_at'], 'updated_at' => $data['updated_at']); $t->is($articleForm->getValues(), $values); $articleForm->save(); $expected = array('id' => $article->id, 'author_id' => $article->Author->id, 'is_on_homepage' => true, 'created_at' => $article->created_at, 'updated_at' => $article->updated_at, 'Translation' => array('en' => array('id' => $article->id, 'title' => 'english title', 'body' => 'english body', 'test_column' => '', 'lang' => 'en', 'slug' => 'english-title'), 'fr' => array('id' => $article->id, 'title' => 'french title', 'body' => 'french body', 'test_column' => '', 'lang' => 'fr', 'slug' => 'french-title')), 'Author' => array('id' => $article->Author->id, 'name' => 'i18n author test', 'type' => null)); $t->is($article->toArray(true), $expected); $articleForm = new MyArticleForm($article); $expected = array('id' => $article->id, 'author_id' => $article->author_id, 'is_on_homepage' => true, 'created_at' => $article->created_at, 'updated_at' => $article->updated_at, 'en' => array('id' => $article->id, 'title' => 'english title', 'body' => 'english body', 'test_column' => '', 'lang' => 'en', 'slug' => 'english-title'), 'fr' => array('id' => $article->id, 'title' => 'french title', 'body' => 'french body', 'test_column' => '', 'lang' => 'fr', 'slug' => 'french-title'), 'Author' => array('id' => $article->Author->id, 'name' => 'i18n author test', 'type' => null)); $t->is($articleForm->getDefaults(), $expected); $article = new Article(); sfContext::getInstance()->getUser()->setCulture('en'); $article->title = 'test'; sfContext::getInstance()->getUser()->setCulture('fr'); $t->is($article->title, 'test');
'test_column' => '', 'lang' => 'fr', 'slug' => 'french-title', ), 'Author' => array( 'name' => 'i18n author test', 'type' => null ), ); $articleForm->bind($data); $t->is($articleForm->isValid(), true); $article = new Article(); $articleForm = new MyArticleForm($article); $data = array( 'is_on_homepage' => 1, 'Author' => array( 'name' => 'i18n author test', 'type' => null), 'en' => array( 'title' => 'english title', 'body' => 'english body'), 'fr' => array( 'title' => 'french title', 'body' => 'french body'), 'created_at' => time(), 'updated_at' => time(), );
public function configure() { parent::configure(); $this->embedI18n(array('en', 'fr')); $authorForm = new AuthorForm($this->object->Author); unset($authorForm['id']); $this->embedForm('Author', $authorForm); unset($this['author_id']); } public function updateDefaultsFromObject() { parent::updateDefaultsFromObject(); } } $article = new Article(); $articleForm = new MyArticleForm($article); $data = array('is_on_homepage' => 1, 'Author' => array('name' => 'i18n author test'), 'en' => array('title' => 'english title', 'body' => 'english body'), 'fr' => array('title' => 'french title', 'body' => 'french body')); $articleForm->bind($data); $t->is($articleForm->isValid(), true); $values = array('is_on_homepage' => true, 'Author' => array('name' => 'i18n author test'), 'en' => array('title' => 'english title', 'body' => 'english body', 'test_column' => '', 'slug' => ''), 'fr' => array('title' => 'french title', 'body' => 'french body', 'test_column' => '', 'slug' => ''), 'id' => null, 'created_at' => null, 'updated_at' => null); $t->is($articleForm->getValues(), $values); $articleForm->save(); $expected = array('id' => $article->id, 'author_id' => $article->Author->id, 'is_on_homepage' => true, 'created_at' => $article->created_at, 'updated_at' => $article->updated_at, 'Translation' => array('en' => array('id' => $article->id, 'title' => 'english title', 'body' => 'english body', 'test_column' => '', 'lang' => 'en', 'slug' => 'english-title'), 'fr' => array('id' => $article->id, 'title' => 'french title', 'body' => 'french body', 'test_column' => '', 'lang' => 'fr', 'slug' => 'french-title')), 'Author' => array('id' => $article->Author->id, 'name' => 'i18n author test')); $t->is($article->toArray(true), $expected); $articleForm->updateDefaultsFromObject(); $expected = array('id' => $article->id, 'author_id' => $article->author_id, 'is_on_homepage' => true, 'created_at' => $article->created_at, 'updated_at' => $article->updated_at, 'en' => array('id' => $article->id, 'title' => 'english title', 'body' => 'english body', 'test_column' => '', 'lang' => 'en', 'slug' => 'english-title'), 'fr' => array('id' => $article->id, 'title' => 'french title', 'body' => 'french body', 'test_column' => '', 'lang' => 'fr', 'slug' => 'french-title'), 'Author' => array('id' => $article->Author->id, 'name' => 'i18n author test')); $t->is($articleForm->getDefaults(), $expected); $article = new Article(); sfContext::getInstance()->getUser()->setCulture('en'); $article->title = 'test'; sfContext::getInstance()->getUser()->setCulture('fr');