11<?php
22namespace PHPForm \Fields ;
33
4- use Fleshgrinder \Core \Formatter ;
5-
6- use PHPForm \PHPFormConfig ;
7- use PHPForm \Utils \Attributes ;
4+ use PHPForm \Config ;
85
96class BoundField
107{
8+ const TEMPLATE_LABEL = "label.html " ;
9+
1110 private $ form ;
1211 private $ field ;
1312 private $ name ;
14- private $ subwidgets_cache ;
13+ private $ options_cache ;
1514
1615 public $ html_name ;
1716 public $ help_text ;
@@ -55,22 +54,21 @@ public function __get($name)
5554 return $ this ->getValue ();
5655 }
5756
58- if ($ name == 'choices ' ) {
59- if (!isset ($ subwidgets_cache )) {
60- $ subwidgets_cache = $ this ->getSubWidgets ();
57+ if ($ name == 'options ' ) {
58+ if (!isset ($ options_cache )) {
59+ $ options_cache = $ this ->getOptions ();
6160 }
62- return $ subwidgets_cache ;
61+ return $ options_cache ;
6362 }
6463
65- return parent :: __get ( $ name ) ;
64+ return null ;
6665 }
6766
68- private function getSubWidgets (array $ attrs = array ())
67+ private function getOptions (array $ attrs = array ())
6968 {
70- $ widget = $ this ->field ->getWidget ();
7169 $ attrs = $ this ->buildWidgetAttrs ($ attrs );
7270
73- return $ widget -> getSubWidgets ($ this ->html_name , $ this ->getValue (), $ attrs );
71+ return $ this -> field -> getWidget ()-> getOptions ($ this ->html_name , $ this ->getValue (), $ attrs );
7472 }
7573
7674 protected function asWidget ($ widget = null , array $ attrs = array ())
@@ -79,31 +77,26 @@ protected function asWidget($widget = null, array $attrs = array())
7977
8078 $ attrs = $ this ->buildWidgetAttrs ($ attrs );
8179
82- return $ widget ->render ($ this ->html_name , $ this ->getValue (), $ attrs );
80+ return $ widget ->render ($ this ->html_name , $ this ->getValue (), $ this -> label , $ attrs );
8381 }
8482
85- public function labelTag ($ contents = null , array $ attrs = null )
83+ public function labelTag ($ contents = null , array $ attrs = array () )
8684 {
8785 $ contents = is_null ($ contents ) ? $ this ->label : $ contents ;
8886
8987 if (empty ($ contents )) {
9088 return "" ;
9189 }
9290
93- if (!is_null ($ attrs )) {
94- $ attrs = Attributes::flatatt ($ attrs );
95- }
96-
9791 $ widget = $ this ->field ->getWidget ();
9892
99- $ label_tpl = PHPFormConfig::getITemplate ("LABEL " );
100- $ label_required_tpl = PHPFormConfig::getITemplate ("LABEL_REQUIRED " );
93+ $ renderer = Config::getInstance ()->getRenderer ();
10194
102- return Formatter:: format ( $ label_tpl , array (
95+ return $ renderer -> render ( self :: TEMPLATE_LABEL , array (
10396 "for " => $ widget ->buildAutoId ($ this ->html_name ),
10497 "attrs " => $ attrs ,
10598 "contents " => $ contents ,
106- "required " => $ this ->field ->isRequired () ? $ label_required_tpl : null
99+ "required " => $ this ->field ->isRequired ()
107100 ));
108101 }
109102
0 commit comments