value = $value; $this->column = $column; if ($extra) { $this->extra = array_merge($this->extra, $extra); } } /** * Get the form field for this field. * * We put this method at the field level as it allows us to easily * create a new DB field and a new Form field and use them without * the need to modify another place where the mapping would be * performed. * * @param array Definition of the field. * @param string Form field class. */ function formField($def, $form_field='Pluf_Form_Field_Varchar') { Pluf::loadClass('Pluf_Form_BoundField'); // To get mb_ucfirst $defaults = array('required' => !$def['blank'], 'label' => mb_ucfirst($def['verbose']), 'help_text' => $def['help_text']); unset($def['blank'], $def['verbose'], $def['help_text']); if (isset($def['default'])) { $defaults['initial'] = $def['default']; unset($def['default']); } if (isset($def['choices'])) { $defaults['widget'] = 'Pluf_Form_Widget_SelectInput'; if (isset($def['widget_attrs'])) { $def['widget_attrs']['choices'] = $def['choices']; } else { $def['widget_attrs'] = array('choices' => $def['choices']); } } foreach (array_keys($def) as $key) { if (!in_array($key, array('widget', 'label', 'required', 'multiple', 'initial', 'choices', 'widget_attrs'))) { unset($def[$key]); } } $params = array_merge($defaults, $def); return new $form_field($params); } }