Development

Changeset 17084

You must first sign up to be able to contribute.

Changeset 17084

Show
Ignore:
Timestamp:
04/07/09 14:39:32 (4 years ago)
Author:
Kris.Wallsmith
Message:

[sfViewableFormPlugin] added support for form formatters

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfViewableFormPlugin/trunk/README

    r17007 r17084  
    88    forms: 
    99      sfGuardFormSignin: 
     10        _formatter: mySigninFormFormatter 
    1011        username: 
    1112          help: Please enter the username you selected during signup. 
    1213        _post_validator: 
    1314          invalid: The username and password you entered were not recognized. 
     15      sfGuardUserForm: 
     16        _formatter: list 
    1417 
    1518    widgets: 
     
    2124        invalid: '"%value%" is not a valid email address.' 
    2225 
     26    formatters: 
     27      list:   myWidgetFormSchemaFormatterList 
     28      custom: myWidgetFormSchemaFormatterCustom 
     29 
    2330The effect of this configuration file is just as it appears. Custom error 
    2431messages will be added to the `sfGuardFormSignin` form, the CSS class "text" 
    2532will be added to all instances of `sfWidgetFormInput`, and a custom error 
    26 message will be added to all instances of `sfValidatorEmail`. 
     33message will be added to all instances of `sfValidatorEmail`. The 
     34`sfGuardFormSignin` form will use the `mySigninFormFormatter` formatter and 
     35`sfGuardUserForm` will use the `myWidgetFormSchemaFormatterList` formatter. 
    2736 
    2837## Model forms 
  • plugins/sfViewableFormPlugin/trunk/lib/form/sfViewableForm.class.php

    r17080 r17084  
    154154  protected function enhanceFormFields(sfFormFieldSchema $fieldSchema, $formClass, array $embeddedForms = array(), $object = null) 
    155155  { 
     156    // enhance schemas 
     157    $this->enhanceWidget($fieldSchema->getWidget(), $object); 
     158    if ($fieldSchema->hasError()) 
     159    { 
     160      $this->enhanceValidator($fieldSchema->getError()->getValidator(), $object); 
     161    } 
     162 
    156163    // loop through the fields and apply the global configuration 
    157164    foreach ($fieldSchema as $field) 
     
    200207        { 
    201208          $params = $this->replaceConstants($params, $object); 
     209 
     210          if ('_formatter' == $name) 
     211          { 
     212            $fieldSchema->getWidget()->setFormFormatterName($params); 
     213 
     214            // parameter can be a class name 
     215            if (class_exists($params) && is_subclass_of($params, 'sfWidgetFormSchemaFormatter')) 
     216            { 
     217              $fieldSchema->getWidget()->addFormFormatter($params, new $params($fieldSchema->getWidget())); 
     218            } 
     219 
     220            continue; 
     221          } 
    202222 
    203223          if (preg_match('/^_(pre|post)_validator$/', $name, $match)) 
     
    249269  public function enhanceWidget(sfWidget $widget, $object = null) 
    250270  { 
     271    // form formatters 
     272    if ($widget instanceof sfWidgetFormSchema) 
     273    { 
     274      $name = $widget->getFormFormatterName(); 
     275      if (isset($this->config['formatters'][$name])) 
     276      { 
     277        $formatter = $this->config['formatters'][$name]; 
     278        $widget->addFormFormatter($name, new $formatter($widget)); 
     279      } 
     280    } 
     281 
    251282    foreach (self::getLineage($widget) as $class) 
    252283    {