Development

Changeset 19968

You must first sign up to be able to contribute.

Changeset 19968

Show
Ignore:
Timestamp:
07/07/09 00:34:57 (7 months ago)
Author:
Jonathan.Wage
Message:

[1.3] sfDoctrinePlugin: added ability to disable the generation of forms and filter classes for a model

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.3/UPGRADE_TO_1_3

    r19960 r19968  
    282282Doctrine 1.2 version. You can read about what is new in Doctrine 1.2  
    283283[here](http://www.doctrine-project.org/upgrade/1_2). 
     284 
     285### Generating Form Classes 
     286 
     287It is now possible to specify additional options for symfony in your Doctrine YAML 
     288schema files. We've added some options to disable the generation of form and filter 
     289classes. 
     290 
     291For example in a typical many to many reference model, you don't need any form  
     292or filter form classes generated. So you can now do the following. 
     293 
     294    UserGroup: 
     295      options: 
     296        symfony: 
     297          form: false 
     298          filter: false 
     299      columns: 
     300        user_id: 
     301          type: integer 
     302          primary: true 
     303        group_id: 
     304          type: integer 
     305          primary: true 
  • branches/1.3/lib/plugins/sfDoctrinePlugin/lib/generator/sfDoctrineFormFilterGenerator.class.php

    r14200 r19968  
    332332    return $php; 
    333333  } 
     334 
     335  /** 
     336   * Filter out models that have disabled generation of form classes 
     337   * 
     338   * @return array $models Array of models to generate forms for 
     339   */ 
     340  protected function filterModels($models) 
     341  { 
     342    foreach ($models as $key => $model) 
     343    { 
     344      $table = Doctrine::getTable($model); 
     345      $symfonyOptions = $table->getOption('symfony'); 
     346 
     347      if (isset($symfonyOptions['filter']) && !$symfonyOptions['filter']) 
     348      { 
     349        unset($models[$key]); 
     350      } 
     351    } 
     352 
     353    return $models; 
     354  } 
    334355} 
  • branches/1.3/lib/plugins/sfDoctrinePlugin/lib/generator/sfDoctrineFormGenerator.class.php

    r19274 r19968  
    603603    $models = Doctrine::getLoadedModels(); 
    604604    $models =  Doctrine::initializeModels($models); 
    605     $this->models = Doctrine::filterInvalidModels($models); 
     605    $models = Doctrine::filterInvalidModels($models); 
     606    $this->models = $this->filterModels($models); 
     607 
    606608    return $this->models; 
     609  } 
     610 
     611  /** 
     612   * Filter out models that have disabled generation of form classes 
     613   * 
     614   * @return array $models Array of models to generate forms for 
     615   */ 
     616  protected function filterModels($models) 
     617  { 
     618    foreach ($models as $key => $model) 
     619    { 
     620      $table = Doctrine::getTable($model); 
     621      $symfonyOptions = $table->getOption('symfony'); 
     622 
     623      if (isset($symfonyOptions['form']) && !$symfonyOptions['form']) 
     624      { 
     625        unset($models[$key]); 
     626      } 
     627    } 
     628 
     629    return $models; 
    607630  } 
    608631 
  • branches/1.3/lib/plugins/sfDoctrinePlugin/test/functional/fixtures/config/doctrine/schema.yml

    r19274 r19968  
    7171      type: unique 
    7272 
    73  
    7473Profile: 
    7574  columns: 
     
    9695 
    9796UserGroup: 
     97  options: 
     98    symfony: 
     99      form: false 
     100      filter: false 
    98101  columns: 
    99102    user_id: 
     
    105108 
    106109UserPermission: 
     110  options: 
     111    symfony: 
     112      form: false 
     113      filter: false 
    107114  columns: 
    108115    user_id: 
     
    114121 
    115122GroupPermission: 
     123  options: 
     124    symfony: 
     125      form: false 
     126      filter: false 
    116127  columns: 
    117128    group_id: 
     
    121132      type: integer 
    122133      primary: true 
     134 
     135FormGeneratorTest: 
     136  options: 
     137    symfony: 
     138      form: true 
     139      filter: false 
     140  columns: 
     141    name: string(255) 
     142 
     143FormGeneratorTest2: 
     144  options: 
     145    symfony: 
     146      form: false 
     147      filter: true 
     148  columns: 
     149    name: string(255) 
  • branches/1.3/lib/plugins/sfDoctrinePlugin/test/functional/fixtures/data/sql/schema.sql

    r19274 r19968  
    22CREATE TABLE author (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(255)); 
    33CREATE TABLE camel_case (id INTEGER PRIMARY KEY AUTOINCREMENT, testcamelcase VARCHAR(255)); 
     4CREATE TABLE form_generator_test (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(255)); 
     5CREATE TABLE form_generator_test2 (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(255)); 
    46CREATE TABLE groups (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(255)); 
    57CREATE TABLE group_permission (group_id INTEGER, permission_id INTEGER, PRIMARY KEY(group_id, permission_id)); 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.