@@ -20,6 +20,9 @@ |
||
20 | 20 | class DataForm extends Widget { |
21 | 21 | use FormTrait; |
22 | 22 | |
23 | + /** |
|
24 | + * @param string $identifier |
|
25 | + */ |
|
23 | 26 | public function __construct($identifier, $modelInstance=NULL) { |
24 | 27 | parent::__construct($identifier, null,$modelInstance); |
25 | 28 | $this->_init(new FormInstanceViewer($identifier), "form", new HtmlForm($identifier), true); |
@@ -55,14 +55,14 @@ |
||
55 | 55 | foreach ($values as $v){ |
56 | 56 | $form->addField($v); |
57 | 57 | } |
58 | - }else{ |
|
58 | + } else{ |
|
59 | 59 | $separators[]=$count; |
60 | 60 | for($i=0;$i<$size;$i++){ |
61 | 61 | $fields=\array_slice($values, $separators[$i]+1,$separators[$i+1]-$separators[$i]); |
62 | 62 | //TODO check why $fields is empty |
63 | 63 | if(\sizeof($fields)===1){ |
64 | 64 | $form->addField($fields[0]); |
65 | - }elseif(\sizeof($fields)>1){ |
|
65 | + } elseif(\sizeof($fields)>1){ |
|
66 | 66 | $form->addFields($fields); |
67 | 67 | $i+=\sizeof($fields)-1; |
68 | 68 | } |
@@ -17,7 +17,14 @@ discard block |
||
17 | 17 | |
18 | 18 | trait FormFieldAsTrait{ |
19 | 19 | |
20 | + /** |
|
21 | + * @param string $prefix |
|
22 | + */ |
|
20 | 23 | abstract protected function _getFieldIdentifier($prefix); |
24 | + |
|
25 | + /** |
|
26 | + * @param \Closure $callback |
|
27 | + */ |
|
21 | 28 | abstract public function setValueFunction($index,$callback); |
22 | 29 | abstract protected function _applyAttributes($element,&$attributes,$index); |
23 | 30 | abstract public function getIdentifier(); |
@@ -39,6 +46,10 @@ discard block |
||
39 | 46 | } |
40 | 47 | } |
41 | 48 | |
49 | + /** |
|
50 | + * @param \Closure $elementCallback |
|
51 | + * @param string $prefix |
|
52 | + */ |
|
42 | 53 | protected function _fieldAs($elementCallback,$index,$attributes=NULL,$prefix=null){ |
43 | 54 | $this->setValueFunction($index,function($value) use ($index,&$attributes,$elementCallback){ |
44 | 55 | $caption=$this->_instanceViewer->getCaption($index); |
@@ -54,9 +54,9 @@ discard block |
||
54 | 54 | $rules=$attributes["rules"]; |
55 | 55 | if(\is_array($rules)){ |
56 | 56 | $element->addRules($rules); |
57 | + } else { |
|
58 | + $element->addRule($rules); |
|
57 | 59 | } |
58 | - else |
|
59 | - $element->addRule($rules); |
|
60 | 60 | unset($attributes["rules"]); |
61 | 61 | } |
62 | 62 | } |
@@ -108,8 +108,9 @@ discard block |
||
108 | 108 | public function fieldAsHeader($index,$niveau=1,$icon=NULL,$attributes=NULL){ |
109 | 109 | return $this->_fieldAs(function($id,$name,$value) use($niveau,$icon){ |
110 | 110 | $header=new HtmlHeader($id,$niveau,$value); |
111 | - if(isset($icon)) |
|
112 | - $header->asIcon($icon, $value); |
|
111 | + if(isset($icon)) { |
|
112 | + $header->asIcon($icon, $value); |
|
113 | + } |
|
113 | 114 | return $header; |
114 | 115 | }, $index,$attributes,"header"); |
115 | 116 | } |
@@ -117,7 +118,9 @@ discard block |
||
117 | 118 | |
118 | 119 | public function fieldAsImage($index,$size=Size::MINI,$circular=false){ |
119 | 120 | $this->setValueFunction($index,function($img) use($size,$circular){ |
120 | - $image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular)$image->setCircular(); |
|
121 | + $image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular) { |
|
122 | + $image->setCircular(); |
|
123 | + } |
|
121 | 124 | return $image; |
122 | 125 | }); |
123 | 126 | return $this; |