@@ -18,6 +18,10 @@ discard block |
||
| 18 | 18 | trait FieldAsTrait{ |
| 19 | 19 | |
| 20 | 20 | abstract protected function _getFieldIdentifier($prefix); |
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * @param \Closure $callback |
|
| 24 | + */ |
|
| 21 | 25 | abstract public function setValueFunction($index,$callback); |
| 22 | 26 | |
| 23 | 27 | private function _getLabelField($caption,$icon=NULL){ |
@@ -27,6 +31,10 @@ discard block |
||
| 27 | 31 | |
| 28 | 32 | protected function _addRules($element,$attributes){} |
| 29 | 33 | |
| 34 | + /** |
|
| 35 | + * @param \Closure $elementCallback |
|
| 36 | + * @param string $prefix |
|
| 37 | + */ |
|
| 30 | 38 | protected function _fieldAs($elementCallback,$index,$attributes=NULL,$prefix=null){ |
| 31 | 39 | $this->setValueFunction($index,function($value)use ($index,&$attributes,$elementCallback,$prefix){ |
| 32 | 40 | $name=$this->_instanceViewer->getCaption($index)."[]"; |
@@ -34,8 +34,9 @@ discard block |
||
| 34 | 34 | $name=$attributes["name"]; |
| 35 | 35 | } |
| 36 | 36 | $element=$elementCallback($this->_getFieldIdentifier($prefix),$value,$name); |
| 37 | - if(\is_array($attributes)) |
|
| 38 | - $this->_applyAttributes($element, $attributes,$index); |
|
| 37 | + if(\is_array($attributes)) { |
|
| 38 | + $this->_applyAttributes($element, $attributes,$index); |
|
| 39 | + } |
|
| 39 | 40 | return $element; |
| 40 | 41 | }); |
| 41 | 42 | return $this; |
@@ -68,7 +69,9 @@ discard block |
||
| 68 | 69 | |
| 69 | 70 | public function fieldAsImage($index,$size=Size::SMALL,$circular=false){ |
| 70 | 71 | $this->setValueFunction($index,function($img) use($size,$circular){ |
| 71 | - $image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular)$image->setCircular(); |
|
| 72 | + $image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular) { |
|
| 73 | + $image->setCircular(); |
|
| 74 | + } |
|
| 72 | 75 | return $image; |
| 73 | 76 | }); |
| 74 | 77 | return $this; |
@@ -16,7 +16,14 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | trait FormFieldAsTrait{ |
| 18 | 18 | |
| 19 | + /** |
|
| 20 | + * @param string $prefix |
|
| 21 | + */ |
|
| 19 | 22 | abstract protected function _getFieldIdentifier($prefix); |
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @param \Closure $callback |
|
| 26 | + */ |
|
| 20 | 27 | abstract public function setValueFunction($index,$callback); |
| 21 | 28 | |
| 22 | 29 | private function _getLabelField($caption,$icon=NULL){ |
@@ -40,6 +47,9 @@ discard block |
||
| 40 | 47 | $element->fromArray($attributes); |
| 41 | 48 | } |
| 42 | 49 | |
| 50 | + /** |
|
| 51 | + * @param HtmlFormField $element |
|
| 52 | + */ |
|
| 43 | 53 | protected function _addRules($element,$attributes){ |
| 44 | 54 | if(isset($attributes["rules"])){ |
| 45 | 55 | $rules=$attributes["rules"]; |
@@ -51,6 +61,9 @@ discard block |
||
| 51 | 61 | } |
| 52 | 62 | } |
| 53 | 63 | |
| 64 | + /** |
|
| 65 | + * @param \Closure $elementCallback |
|
| 66 | + */ |
|
| 54 | 67 | protected function _fieldAs($elementCallback,$index,$attributes=NULL,$identifier=null){ |
| 55 | 68 | $this->setValueFunction($index,function($value)use ($index,&$attributes,$elementCallback){ |
| 56 | 69 | $caption=$this->_instanceViewer->getCaption($index); |
@@ -43,10 +43,11 @@ discard block |
||
| 43 | 43 | protected function _addRules($element,$attributes){ |
| 44 | 44 | if(isset($attributes["rules"])){ |
| 45 | 45 | $rules=$attributes["rules"]; |
| 46 | - if(\is_array($rules)) |
|
| 47 | - $element->addRules($rules); |
|
| 48 | - else |
|
| 49 | - $element->addRule($rules); |
|
| 46 | + if(\is_array($rules)) { |
|
| 47 | + $element->addRules($rules); |
|
| 48 | + } else { |
|
| 49 | + $element->addRule($rules); |
|
| 50 | + } |
|
| 50 | 51 | unset($attributes["rules"]); |
| 51 | 52 | } |
| 52 | 53 | } |
@@ -56,8 +57,9 @@ discard block |
||
| 56 | 57 | $caption=$this->_instanceViewer->getCaption($index); |
| 57 | 58 | $name=$this->_instanceViewer->getFieldName($index); |
| 58 | 59 | $element=$elementCallback($name,$caption,$value); |
| 59 | - if(\is_array($attributes)) |
|
| 60 | - $this->_applyAttributes($element, $attributes,$index); |
|
| 60 | + if(\is_array($attributes)) { |
|
| 61 | + $this->_applyAttributes($element, $attributes,$index); |
|
| 62 | + } |
|
| 61 | 63 | return $element; |
| 62 | 64 | }); |
| 63 | 65 | return $this; |