1010
1111abstract class ChoiceWidget extends Widget
1212{
13- const TEMPLATE_OPTION = "" ;
13+ const TEMPLATE_CHOICE = "" ;
1414
1515 protected $ allow_multiple_selected = false ;
1616 protected $ input_type = null ;
@@ -21,9 +21,9 @@ abstract class ChoiceWidget extends Widget
2121 /**
2222 * The constructor.
2323 */
24- public function __construct (array $ choices = array (), array $ css_classes = null , array $ attrs = null )
24+ public function __construct (array $ choices = array (), array $ attrs = null )
2525 {
26- parent ::__construct ($ css_classes , $ attrs );
26+ parent ::__construct ($ attrs );
2727
2828 $ this ->setChoices ($ choices );
2929 }
@@ -36,14 +36,17 @@ public function setChoices(array $choices)
3636 public function getContext (string $ name , $ value , array $ attrs = null )
3737 {
3838 $ context = parent ::getContext ($ name , $ value , $ attrs );
39- $ context ["options " ] = $ this ->renderOptions ($ context ["name " ], $ context ["value " ], $ attrs );
39+
40+ $ context ["options " ] = implode ($ this ->getSubWidgets ($ name , $ value , $ attrs ));
4041
4142 return $ context ;
4243 }
4344
44- public function renderOptions (string $ name , $ value , array $ attrs = null )
45+ public function getSubWidgets (string $ name , $ value , array $ attrs = null )
4546 {
46- $ options = "" ;
47+ $ value = $ this ->formatValue ($ value );
48+ $ subwidgets = array ();
49+
4750 $ index = 1 ;
4851 $ has_selected = false ;
4952
@@ -55,17 +58,17 @@ public function renderOptions(string $name, $value, array $attrs = null)
5558 $ has_selected = true ;
5659 }
5760
58- $ context = $ this ->getOptionContext ($ name , $ choice_value , $ choice_label , $ selected , $ index , $ attrs );
61+ $ context = $ this ->getSubWidgetContext ($ name , $ choice_value , $ choice_label , $ selected , $ index , $ attrs );
5962
60- $ options . = Formatter::format (static ::TEMPLATE_OPTION , $ context );
63+ $ subwidgets [] = Formatter::format (static ::TEMPLATE_CHOICE , $ context );
6164
6265 $ index ++;
6366 }
6467
65- return $ options ;
68+ return $ subwidgets ;
6669 }
6770
68- public function getOptionContext (
71+ public function getSubWidgetContext (
6972 string $ name ,
7073 $ value ,
7174 string $ label ,
@@ -78,7 +81,7 @@ public function getOptionContext(
7881 }
7982
8083 if ($ this ->option_inherits_attrs ) {
81- $ attrs [" id " ] = $ this ->buildAutoId ($ name , $ index );
84+ $ attrs [' id ' ] = $ this ->buildAutoId ($ name , $ index );
8285 }
8386
8487 if ($ is_selected ) {
@@ -88,7 +91,7 @@ public function getOptionContext(
8891 return array (
8992 "for " => $ this ->buildAutoId ($ name , $ index ),
9093 "type " => $ this ->input_type ,
91- "name " => $ name ,
94+ "name " => htmlentities ( $ name) ,
9295 "value " => htmlentities ($ value ),
9396 "label " => htmlentities ($ label ),
9497 "attrs " => Attributes::flatatt ($ attrs ),
0 commit comments