if ($key !== 'widget_attrs')
$this->$key = $m[$key];
}
- $widget_name = $this->getWidget();
- if (isset($params['widget_attrs'])) {
- $attrs = $params['widget_attrs'];
- } else {
- $attrs = array();
- }
- $widget = new $widget_name($attrs);
- $attrs = $this->widgetAttrs($widget);
- if (count($attrs)) {
- $widget->attrs = array_merge($widget->attrs, $attrs);
- }
- $this->widget = $widget;
+
+ $widget_attrs = isset($params['widget_attrs']) ? $params['widget_attrs'] : array();
+ $this->widget = $this->createWidget($widget_attrs);
}
public function clean($value)
function LateClean($data, &$cleaned_data){
}
- protected function getWidget(){
- return $this->widget;
- }
-
- public function widgetAttrs($widget)
+ protected function createWidget($args)
{
- return array();
+ $widgetClass = $this->widget;
+ return new $widgetClass($args);
}
}
<?php
-class IPF_Form_Field_Html extends IPF_Form_Field_Varchar{
- protected function getWidget(){
- return 'IPF_Form_Widget_HTMLInput';
- }
-}
\ No newline at end of file
+class IPF_Form_Field_Html extends IPF_Form_Field_Varchar
+{
+ public $widget = 'IPF_Form_Widget_HTMLInput';
+}
+
return $value;
}
- public function widgetAttrs($widget)
+ protected function createWidget($args)
{
- if ($this->max_length !== null and in_array(get_class($widget), array('IPF_Form_Widget_TextInput', 'IPF_Form_Widget_PasswordInput'))) {
- return array('maxlength'=>$this->max_length);
+ if ($this->max_length > 255) {
+ $widgetClass = 'IPF_Form_Widget_TextareaInput';
+ } else {
+ $widgetClass = $this->widget;
+ if ($this->max_length !== null)
+ $args['maxlength'] = $this->max_length;
}
- return array();
- }
-
- protected function getWidget()
- {
- if ($this->max_length>255)
- return 'IPF_Form_Widget_TextareaInput';
- return $this->widget;
+ return new $widgetClass($args);
}
}