Development

Changeset 11185 for plugins/sfFormtasticPlugin

You must first sign up to be able to contribute.

Show
Ignore:
Timestamp:
08/27/08 01:42:03 (5 years ago)
Author:
Kris.Wallsmith
Message:

sfFormtasticPlugin: Fixed sfFormtasticBase::setIdFormat() (refs #4153), cleaned up render methods for better DRY.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfFormtasticPlugin/trunk/lib/form/sfFormtasticBase.class.php

    r10453 r11185  
    107107  { 
    108108    $this->checkCSRFField(); 
    109     $this->applyIdFormat(); 
    110109     
    111110    return parent::render($attributes); 
     
    119118  public function renderHiddenFields() 
    120119  { 
    121     $this->checkCSRFField()
    122     $this->applyIdFormat(); 
    123      
    124     $rendered = array(); 
    125     foreach ($this->getFormFieldSchema()->getHiddenFields() as $field) 
    126     { 
    127       $rendered[] = $field->render(); 
    128     } 
    129      
    130     return join("\n", $rendered); 
     120    $clone = clone $this
     121    foreach ($clone->getFormFieldSchema() as $name => $field) 
     122    { 
     123      if (!$field->isHidden()) 
     124      { 
     125        unset($clone[$name]); 
     126      } 
     127    } 
     128     
     129    return $clone->render(); 
    131130  } 
    132131   
     
    143142    } 
    144143     
    145     $this->setOption('id_format', $format); 
     144    $this->widgetSchema->setOption('id_format', $format); 
    146145  } 
    147146   
     
    153152  public function getIdFormat() 
    154153  { 
    155     return $this->getOption('id_format'); 
    156   } 
    157    
    158   /** 
    159    * Apply id format to the widgets, if configured. 
    160    */ 
    161   protected function applyIdFormat() 
    162   { 
    163     if (!is_null($format = $this->getIdFormat())) 
    164     { 
    165       foreach ($this->widgetSchema->getFields() as $widget) 
    166       { 
    167         if ($widget instanceof sfWidgetForm) 
    168         { 
    169           $widget->setIdFormat($format); 
    170         } 
    171       } 
    172     } 
     154    return $this->widgetSchema->getOption('id_format'); 
    173155  } 
    174156   
     
    214196  public function removeField($name) 
    215197  { 
    216     unset($name); 
     198    unset($this[$name]); 
    217199  } 
    218200   
  • plugins/sfFormtasticPlugin/trunk/lib/form/sfFormtasticFieldSchemaBase.class.php

    r10209 r11185  
    1414class sfFormtasticFieldSchemaBase extends sfFormFieldSchema 
    1515{ 
    16   /** 
    17    * @return array All hidden form fields 
    18    */ 
    19   public function getHiddenFields() 
    20   { 
    21     $hiddenFields = array(); 
    22     foreach ($this as $field) 
    23     { 
    24       if ($field->isHidden()) 
    25       { 
    26         $hiddenFields[] = $field; 
    27       } 
    28     } 
    29      
    30     return $hiddenFields; 
    31   } 
    3216} 
  • plugins/sfFormtasticPlugin/trunk/test/unit/sfFormtasticBaseTest.php

    r10535 r11185  
    3535$t->diag('->setIdFormat()'); 
    3636 
     37try 
     38{ 
     39  $form->setIdFormat('foo'); 
     40  $t->fail('->setIdFormat() throws an exception when parameter does not include "%s"'); 
     41} 
     42catch (InvalidArgumentException $e) 
     43{ 
     44  $t->pass('->setIdFormat() throws an exception when parameter does not include "%s"'); 
     45} 
     46 
    3747$form->setIdFormat('my_id_format_%s'); 
    38 $t->is($form->getOption('id_format'), 'my_id_format_%s', '->setIdFormat() sets the "id_format" option'); 
     48$t->is($form->getWidgetSchema()->getOption('id_format'), 'my_id_format_%s', '->setIdFormat() sets the widgetSchema "id_format" option'); 
    3949$t->is($form->getIdFormat(), 'my_id_format_%s', '->getIdFormat() returns the "id_format" option'); 
    4050$t->like($form->render(), '/id="my_id_format_/', '->render() respects global id format'); 
     
    4252 
    4353$form->setIdFormat(false); 
    44 $t->like($form->render(), '/id="email"/', '"->setIdFormat(false)" resets id attribute on labeled fields'); 
    45 $t->unlike($form->render(), '/id="\w*_csrf_token/', '"->setIdFormat(false)" removes id attribute on non-labeled fields'); 
     54$t->unlike($form->render(), '/id="/', '"->setIdFormat(false)" removes id attribute');