10
10
11
11
abstract class ChoiceWidget extends Widget
12
12
{
13
- const TEMPLATE_OPTION = "" ;
13
+ const TEMPLATE_CHOICE = "" ;
14
14
15
15
protected $ allow_multiple_selected = false ;
16
16
protected $ input_type = null ;
@@ -21,9 +21,9 @@ abstract class ChoiceWidget extends Widget
21
21
/**
22
22
* The constructor.
23
23
*/
24
- public function __construct (array $ choices = array (), array $ css_classes = null , array $ attrs = null )
24
+ public function __construct (array $ choices = array (), array $ attrs = null )
25
25
{
26
- parent ::__construct ($ css_classes , $ attrs );
26
+ parent ::__construct ($ attrs );
27
27
28
28
$ this ->setChoices ($ choices );
29
29
}
@@ -36,14 +36,17 @@ public function setChoices(array $choices)
36
36
public function getContext (string $ name , $ value , array $ attrs = null )
37
37
{
38
38
$ 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 ));
40
41
41
42
return $ context ;
42
43
}
43
44
44
- public function renderOptions (string $ name , $ value , array $ attrs = null )
45
+ public function getSubWidgets (string $ name , $ value , array $ attrs = null )
45
46
{
46
- $ options = "" ;
47
+ $ value = $ this ->formatValue ($ value );
48
+ $ subwidgets = array ();
49
+
47
50
$ index = 1 ;
48
51
$ has_selected = false ;
49
52
@@ -55,17 +58,17 @@ public function renderOptions(string $name, $value, array $attrs = null)
55
58
$ has_selected = true ;
56
59
}
57
60
58
- $ context = $ this ->getOptionContext ($ name , $ choice_value , $ choice_label , $ selected , $ index , $ attrs );
61
+ $ context = $ this ->getSubWidgetContext ($ name , $ choice_value , $ choice_label , $ selected , $ index , $ attrs );
59
62
60
- $ options . = Formatter::format (static ::TEMPLATE_OPTION , $ context );
63
+ $ subwidgets [] = Formatter::format (static ::TEMPLATE_CHOICE , $ context );
61
64
62
65
$ index ++;
63
66
}
64
67
65
- return $ options ;
68
+ return $ subwidgets ;
66
69
}
67
70
68
- public function getOptionContext (
71
+ public function getSubWidgetContext (
69
72
string $ name ,
70
73
$ value ,
71
74
string $ label ,
@@ -78,7 +81,7 @@ public function getOptionContext(
78
81
}
79
82
80
83
if ($ this ->option_inherits_attrs ) {
81
- $ attrs [" id " ] = $ this ->buildAutoId ($ name , $ index );
84
+ $ attrs [' id ' ] = $ this ->buildAutoId ($ name , $ index );
82
85
}
83
86
84
87
if ($ is_selected ) {
@@ -88,7 +91,7 @@ public function getOptionContext(
88
91
return array (
89
92
"for " => $ this ->buildAutoId ($ name , $ index ),
90
93
"type " => $ this ->input_type ,
91
- "name " => $ name ,
94
+ "name " => htmlentities ( $ name) ,
92
95
"value " => htmlentities ($ value ),
93
96
"label " => htmlentities ($ label ),
94
97
"attrs " => Attributes::flatatt ($ attrs ),
0 commit comments