Development

Changeset 22342

You must first sign up to be able to contribute.

Changeset 22342

Show
Ignore:
Timestamp:
09/24/09 12:51:04 (4 years ago)
Author:
alecs
Message:

small fix. moved the 'Form' content to the extractor class

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfI18nFormExtractorPlugin/lib/sfI18nFormExtract.class.php

    r22340 r22342  
    44 * @author     Alexandru Emil Lupu <gang.alecs@gmail.com> 
    55 */ 
    6 class sfI18nFormExtract extends sfI18nExtract  
     6class sfI18nFormExtract extends sfI18nExtract 
    77{ 
    88  protected $extractObjects = array(); 
    99  protected $messages = array(); 
    1010  protected $form = null; 
    11    
     11 
    1212 
    1313  public function setForm($form) 
    1414  { 
     15    $form = $options['form']; 
     16    if ('Form' != substr($form,-4,4)) 
     17    { 
     18      $form .='Form'; 
     19    } 
    1520    $this->form = new $form(); 
    1621  } 
    17    
     22 
    1823  public function extract() 
    1924  { 
     
    2227    $this->updateMessages($this->getFormMessages()); 
    2328  } 
    24    
     29 
    2530  private function getFormMessages(){ 
    2631    return $this->messages; 
    2732  } 
    28    
    29   private function registerErrorMessages(){ 
    30     $field_list = $this->form->getValidatorSchema()->getFields(); 
    31     foreach ($field_list as $field ){ 
    32       $this->merge($field); 
    33     } 
    34     $this->merge($this->form->getValidatorSchema()->getPostValidator()); 
    35     $this->merge($this->form->getValidatorSchema()->getPreValidator()); 
    36   } 
    37    
    3833 
    39   private function merge($field){ 
    40     if (method_exists($field,'getMessages') && method_exists($field,'getValidators')){ 
    41       $this->messages = array_merge($this->messages, $field->getMessages()); 
    42       foreach ($field->getValidators() as $f) { 
    43         $this->merge($f); 
    44       } 
    45     }elseif (method_exists($field,'getMessages')){ 
    46       $this->messages = array_merge($this->messages, $field->getMessages()); 
    47     } 
    48     $this->processMessages(); 
    49   } 
     34  private function registerErrorMessages(){ 
     35    $field_list = $this->form->getValidatorSchema()->getFields(); 
     36    foreach ($field_list as $field ){ 
     37      $this->merge($field); 
     38    } 
     39    $this->merge($this->form->getValidatorSchema()->getPostValidator()); 
     40    $this->merge($this->form->getValidatorSchema()->getPreValidator()); 
     41  } 
    5042 
    51   private function processMessages(){ 
    52     $msg = array(); 
    53     foreach ($this->messages as $key=>$value) { 
    54       $msg[md5($value)] = $value; 
    55     } 
    56     $this->messages = $msg; 
    57   } 
    58    
    59   private function processLabels(){ 
    60     $labels = $this->form->getWidgetSchema()->getLabels(); 
    61     foreach ($labels as $key=>$value){ 
    62       if (empty($value)) 
    63         $this->messages[] = $key; 
    64       else  
    65         $this->messages[] = $value; 
    66     } 
    67     $this->processMessages(); 
    68   } 
     43 
     44  private function merge($field){ 
     45    if (method_exists($field,'getMessages') && method_exists($field,'getValidators')){ 
     46      $this->messages = array_merge($this->messages, $field->getMessages()); 
     47      foreach ($field->getValidators() as $f) { 
     48        $this->merge($f); 
     49      } 
     50    }elseif (method_exists($field,'getMessages')){ 
     51      $this->messages = array_merge($this->messages, $field->getMessages()); 
     52    } 
     53    $this->processMessages(); 
     54  } 
     55 
     56  private function processMessages(){ 
     57    $msg = array(); 
     58    foreach ($this->messages as $key=>$value) { 
     59      $msg[md5($value)] = $value; 
     60    } 
     61    $this->messages = $msg; 
     62  } 
     63 
     64  private function processLabels(){ 
     65    $labels = $this->form->getWidgetSchema()->getLabels(); 
     66    foreach ($labels as $key=>$value){ 
     67      if (empty($value)) 
     68      $this->messages[] = $key; 
     69      else 
     70      $this->messages[] = $value; 
     71    } 
     72    $this->processMessages(); 
     73  } 
    6974} 
  • plugins/sfI18nFormExtractorPlugin/lib/task/sfI18nFormExtractTask.class.php

    r22340 r22342  
    5555    if ($options['form']) 
    5656    { 
    57       $form = $options['form']; 
    58       if ('Form' != substr($form,-4,4)) 
    59       { 
    60         $form .='Form'; 
    61       } 
    6257      $extract->setForm($form); 
    6358      $extract->extract();