Development

Changeset 9501

You must first sign up to be able to contribute.

Changeset 9501

Show
Ignore:
Timestamp:
06/09/08 19:56:13 (2 years ago)
Author:
fabien
Message:

added pre and post validator merge for embedForm and embedFormForEach

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/form/sfForm.class.php

    r9498 r9501  
    270270    $this->widgetSchema[$name] = new sfWidgetFormSchemaDecorator($widgetSchema, $decorator); 
    271271    $this->validatorSchema[$name] = $form->getValidatorSchema(); 
    272      
     272 
     273    $this->mergePreValidator($form->getValidatorSchema()->getPreValidator()); 
     274    $this->mergePostValidator($form->getValidatorSchema()->getPostValidator()); 
     275 
    273276    $this->resetFormFields(); 
    274277  } 
     
    318321    $this->validatorSchema[$name] = new sfValidatorSchemaForEach($form->getValidatorSchema(), $n); 
    319322 
     323    $this->mergePreValidator($form->getValidatorSchema()->getPreValidator()); 
     324    $this->mergePostValidator($form->getValidatorSchema()->getPostValidator()); 
     325 
    320326    $this->resetFormFields(); 
    321327  } 
     
    344350      $this->widgetSchema[$field] = $widget; 
    345351    } 
    346      
     352 
    347353    foreach ($form->getValidatorSchema()->getFields() as $field => $validator) 
    348354    { 
    349355      $this->validatorSchema[$field] = $validator; 
    350356    } 
    351      
    352     if (!is_null($form->getValidatorSchema()->getPreValidator())) 
     357 
     358    $this->mergePreValidator($form->getValidatorSchema()->getPreValidator()); 
     359    $this->mergePostValidator($form->getValidatorSchema()->getPostValidator()); 
     360 
     361    $this->resetFormFields(); 
     362  } 
     363 
     364  /** 
     365   * Merges a validator with the current pre validators. 
     366   * 
     367   * @param sfValidatorBase $validator A validator to be merged 
     368   */ 
     369  public function mergePreValidator(sfValidatorBase $validator = null) 
     370  { 
     371    if (is_null($validator)) 
     372    { 
     373      return; 
     374    } 
     375 
     376    if (is_null($this->validatorSchema->getPreValidator())) 
     377    { 
     378      $this->validatorSchema->setPreValidator($validator); 
     379    } 
     380    else 
    353381    { 
    354382      $this->validatorSchema->setPreValidator(new sfValidatorAnd(array( 
    355         !is_null($this->validatorSchema->getPreValidator()) ? $this->validatorSchema->getPreValidator() : new sfValidatorPass(),  
    356         $form->getValidatorSchema()->getPreValidator()
     383        $this->validatorSchema->getPreValidator(), 
     384        $validator
    357385      ))); 
    358386    } 
    359      
    360     if (!is_null($form->getValidatorSchema()->getPostValidator())) 
     387  } 
     388 
     389  /** 
     390   * Merges a validator with the current post validators. 
     391   * 
     392   * @param sfValidatorBase $validator A validator to be merged 
     393   */ 
     394  public function mergePostValidator(sfValidatorBase $validator = null) 
     395  { 
     396    if (is_null($validator)) 
     397    { 
     398      return; 
     399    } 
     400 
     401    if (is_null($this->validatorSchema->getPostValidator())) 
     402    { 
     403      $this->validatorSchema->setPostValidator($validator); 
     404    } 
     405    else 
    361406    { 
    362407      $this->validatorSchema->setPostValidator(new sfValidatorAnd(array( 
    363         !is_null($this->validatorSchema->getPostValidator()) ? $this->validatorSchema->getPostValidator() : new sfValidatorPass(),  
    364         $form->getValidatorSchema()->getPostValidator()
     408        $this->validatorSchema->getPostValidator(), 
     409        $validator
    365410      ))); 
    366411    } 
    367  
    368     $this->resetFormFields(); 
    369412  } 
    370413 
  • branches/1.1/test/unit/form/sfFormTest.php

    r9498 r9501  
    601601$t->isa_ok($widgetSchema['c'], 'sfWidgetFormTextarea', 'mergeForm() overrides original form widget'); 
    602602$t->isa_ok($validatorSchema['c'], 'sfValidatorPass', 'mergeForm() overrides original form validator'); 
    603 $t->isa_ok($validatorSchema->getPreValidator(), 'sfValidatorAnd', 'mergeForm() merges pre validator'); 
    604 $t->isa_ok($validatorSchema->getPostValidator(), 'sfValidatorAnd', 'mergeForm() merges post validator'); 
     603$t->isa_ok($validatorSchema->getPreValidator(), 'sfValidatorPass', 'mergeForm() merges pre validator'); 
     604$t->isa_ok($validatorSchema->getPostValidator(), 'sfValidatorPass', 'mergeForm() merges post validator'); 
    605605 
    606606try 

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.