Skip to content

servs/nFormEmbedPlugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

nFormEmbedPlugin

Introduction

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.

Setup

Extend nBaseEmbedForm from your BaseFormDoctrine.

before: class BaseFormDoctrine extends sfFormDoctrine { ...

becomes: class BaseFormDoctrine extends nBaseEmbedForm { ...

Usage

Embed a form

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

Diagram

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');
  }

Embed i18n

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'));

Known limitations

  • 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.

Credits

License

This work is published under the Symfony License.

About

nFormEmbedPlugin is a symfony 1.3/1.4 plugin. Created to ease the embedding and saving of related Doctrine 1.2 forms.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published