Development

Changeset 5995

You must first sign up to be able to contribute.

Changeset 5995

Show
Ignore:
Timestamp:
11/13/07 16:50:03 (1 year ago)
Author:
fabien
Message:

added method to sfWidgetFormSchema to manage help messages + added a way to format help messages in formatter classes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/widget/sfWidgetFormSchema.class.php

    r5937 r5995  
    3232    $labels         = array(), 
    3333    $fields         = array(), 
    34     $positions      = array(); 
     34    $positions      = array(), 
     35    $helps          = array(); 
    3536 
    3637  /** 
     
    5152   * @param array An array of options 
    5253   * @param array An array of HTML labels 
     54   * @param array An array of help texts 
    5355   * 
    5456   * @see sfWidgetForm 
    5557   */ 
    56   public function __construct($fields = null, $options = array(), $attributes = array(), $labels = array()
     58  public function __construct($fields = null, $options = array(), $attributes = array(), $labels = array(), $helps = array()
    5759  { 
    5860    if (is_array($fields)) 
     
    186188   * 
    187189   * @param string The field name 
    188    * @param strgin The label name 
     190   * @param string The label name 
    189191   */ 
    190192  public function setLabel($name, $value) 
     
    203205  { 
    204206    return array_key_exists($name, $this->labels) ? $this->labels[$name] : ''; 
     207  } 
     208 
     209  /** 
     210   * Sets the help texts to render for each field. 
     211   * 
     212   * @param array An array of help texts 
     213   */ 
     214  public function setHelps($helps) 
     215  { 
     216    $this->helps = $helps; 
     217  } 
     218 
     219  /** 
     220   * Sets the help texts. 
     221   * 
     222   * @return array An array of help texts 
     223   */ 
     224  public function getHelps() 
     225  { 
     226    return $this->helps; 
     227  } 
     228 
     229  /** 
     230   * Sets a help text. 
     231   * 
     232   * @param string The field name 
     233   * @param string The help text 
     234   */ 
     235  public function setHelp($name, $help) 
     236  { 
     237    $this->helps[$name] = $help; 
     238  } 
     239 
     240  /** 
     241   * Gets a text help by field name. 
     242   * 
     243   * @param  string The field name 
     244   * 
     245   * @return string The help text or an empty string if it is not defined 
     246   */ 
     247  public function getHelp($name) 
     248  { 
     249    return array_key_exists($name, $this->helps) ? $this->helps[$name] : ''; 
    205250  } 
    206251 
     
    309354        $error = $widget instanceof sfWidgetFormSchema ? array() : $error; 
    310355 
    311         $rows[] = $formFormat->formatRow($label, $field, $error); 
     356        $rows[] = $formFormat->formatRow($label, $field, $error, $this->getHelp($name)); 
    312357      } 
    313358    } 
  • trunk/lib/widget/sfWidgetFormSchemaFormatter.class.php

    r5937 r5995  
    1010 
    1111/** 
    12  *  
     12 * sfWidgetFormSchemaFormatter allows to format a form schema with HTML formats. 
    1313 * 
    1414 * @package    symfony 
     
    2121  protected 
    2222    $rowFormat                 = '', 
     23    $helpFormat                = '%help%', 
    2324    $errorRowFormat            = '', 
    2425    $errorListFormatInARow     = "  <ul class=\"error_list\">\n%errors%  </ul>\n", 
     
    3334      '%field%'         => $field, 
    3435      '%error%'         => $this->formatErrorsForRow($errors), 
    35       '%help%'          => $help
     36      '%help%'          => $this->formatHelp($help)
    3637      '%hidden_fields%' => is_null($hiddenFields) ? '%hidden_fields%' : $hiddenFields, 
    3738    )); 
     39  } 
     40 
     41  public function formatHelp($help) 
     42  { 
     43    if (!$help) 
     44    { 
     45      return ''; 
     46    } 
     47 
     48    return strtr($this->getHelpFormat(), array('%help%' => $help)); 
    3849  } 
    3950 
     
    150161    return $this->decoratorFormat; 
    151162  } 
     163 
     164  public function setHelpFormat($format) 
     165  { 
     166    $this->helpFormat = $format; 
     167  } 
     168 
     169  public function getHelpFormat() 
     170  { 
     171    return $this->helpFormat; 
     172  } 
    152173} 
  • trunk/lib/widget/sfWidgetFormSchemaFormatterList.class.php

    r5937 r5995  
    2222    $rowFormat       = "<li>\n  %error%%label%\n  %field%%help%\n%hidden_fields%</li>\n", 
    2323    $errorRowFormat  = "<li>\n%errors%</li>\n", 
     24    $helpFormat      = '<br />%help%', 
    2425    $decoratorFormat = "<ul>\n  %content%</ul>"; 
    2526} 
  • trunk/lib/widget/sfWidgetFormSchemaFormatterTable.class.php

    r5937 r5995  
    2222    $rowFormat       = "<tr>\n  <th>%label%</th>\n  <td>%error%%field%%help%%hidden_fields%</td>\n</tr>\n", 
    2323    $errorRowFormat  = "<tr><td colspan=\"2\">\n%errors%</td></tr>\n", 
     24    $helpFormat      = '<br />%help%', 
    2425    $decoratorFormat = "<table>\n  %content%</table>"; 
    2526}