nFormEmbedPlugin is a Symfony 1.3/1.4 plugin. Created to ease the embedding and saving of related Doctrine 1.2 forms. It's key points are
- Plain & Easy
- embedRelationAndCreate('RelationName');
- easy i18n embedding. Just supply the languages.
Extend nBaseEmbedForm from your BaseFormDoctrine.
before: class BaseFormDoctrine extends sfFormDoctrine { ...
becomes: class BaseFormDoctrine extends nBaseEmbedForm { ...
In the setup() or configure() method of a form call $this->embedRelationAndCreate('RelationName'); that's all. Suppose we have a Doctrine model Author and a model Book. An Author has one or more Books.
--- schema.yml
Author:
columns:
name: string(63)
Book:
columns:
name: string(63)
author_id: integer
relations:
Author:
local: author_id
foreignAlias: Books
In the Author form we call the embedRelationAndCreate() method. This creates a sub form with all the related books and a way to add new books.
class AuthorForm extends BaseAuthorForm {
public function configure() {
// other stuff you might want to do...
$this->embedRelationAndCreate('Books');
}
On any form with i18n fields, just call embedI18n(cultures); The i18n subforms will be included and saved. Example: $form = new BookForm(); $form->embedI18n(array('en', 'nl'));
- No form will be embedded if the parent form doesn't already exists. Otherwise a Doctrine error will occure. The form first tries to save all embeddedForms but doesn't have a corresponding id for the relation field.
- The saveManyToMany() method tries it's best to save all list fields. However if your fields have strange names it might not work.
- A bit more testing with multi-part forms is needed. Not sure if the uploaded file is correctly saved. Just create a bug report.
- Nathan Bijnens (Servs)
- Erik Van Kelst (4levels)
This work is published under the Symfony License.