@@ -70,7 +70,7 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null,
70
70
// If the callable returns null, the choice is not added to any group
71
71
if (\is_callable ($ groupBy )) {
72
72
foreach ($ choices as $ value => $ choice ) {
73
- self ::addChoiceViewGroupedBy (
73
+ self ::addChoiceViewsGroupedByCallable (
74
74
$ groupBy ,
75
75
$ choice ,
76
76
(string ) $ value ,
@@ -83,9 +83,23 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null,
83
83
$ otherViews
84
84
);
85
85
}
86
+
87
+ // Remove empty group views that may have been created by
88
+ // addChoiceViewsGroupedByCallable()
89
+ foreach ($ preferredViews as $ key => $ view ) {
90
+ if ($ view instanceof ChoiceGroupView && 0 === \count ($ view ->choices )) {
91
+ unset($ preferredViews [$ key ]);
92
+ }
93
+ }
94
+
95
+ foreach ($ otherViews as $ key => $ view ) {
96
+ if ($ view instanceof ChoiceGroupView && 0 === \count ($ view ->choices )) {
97
+ unset($ otherViews [$ key ]);
98
+ }
99
+ }
86
100
} else {
87
101
// Otherwise use the original structure of the choices
88
- self ::addChoiceViewsGroupedBy (
102
+ self ::addChoiceViewsFromStructuredValues (
89
103
$ list ->getStructuredValues (),
90
104
$ label ,
91
105
$ choices ,
@@ -98,20 +112,6 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null,
98
112
);
99
113
}
100
114
101
- // Remove any empty group view that may have been created by
102
- // addChoiceViewGroupedBy()
103
- foreach ($ preferredViews as $ key => $ view ) {
104
- if ($ view instanceof ChoiceGroupView && 0 === \count ($ view ->choices )) {
105
- unset($ preferredViews [$ key ]);
106
- }
107
- }
108
-
109
- foreach ($ otherViews as $ key => $ view ) {
110
- if ($ view instanceof ChoiceGroupView && 0 === \count ($ view ->choices )) {
111
- unset($ otherViews [$ key ]);
112
- }
113
- }
114
-
115
115
return new ChoiceListView ($ otherViews , $ preferredViews );
116
116
}
117
117
@@ -150,9 +150,9 @@ private static function addChoiceView($choice, $value, $label, $keys, &$index, $
150
150
}
151
151
}
152
152
153
- private static function addChoiceViewsGroupedBy ( $ groupBy , $ label , $ choices , $ keys , &$ index , $ attr , $ isPreferred , &$ preferredViews , &$ otherViews )
153
+ private static function addChoiceViewsFromStructuredValues ( $ values , $ label , $ choices , $ keys , &$ index , $ attr , $ isPreferred , &$ preferredViews , &$ otherViews )
154
154
{
155
- foreach ($ groupBy as $ key => $ value ) {
155
+ foreach ($ values as $ key => $ value ) {
156
156
if (null === $ value ) {
157
157
continue ;
158
158
}
@@ -162,7 +162,7 @@ private static function addChoiceViewsGroupedBy($groupBy, $label, $choices, $key
162
162
$ preferredViewsForGroup = [];
163
163
$ otherViewsForGroup = [];
164
164
165
- self ::addChoiceViewsGroupedBy (
165
+ self ::addChoiceViewsFromStructuredValues (
166
166
$ value ,
167
167
$ label ,
168
168
$ choices ,
@@ -200,7 +200,7 @@ private static function addChoiceViewsGroupedBy($groupBy, $label, $choices, $key
200
200
}
201
201
}
202
202
203
- private static function addChoiceViewGroupedBy ($ groupBy , $ choice , $ value , $ label , $ keys , &$ index , $ attr , $ isPreferred , &$ preferredViews , &$ otherViews )
203
+ private static function addChoiceViewsGroupedByCallable ($ groupBy , $ choice , $ value , $ label , $ keys , &$ index , $ attr , $ isPreferred , &$ preferredViews , &$ otherViews )
204
204
{
205
205
$ groupLabels = $ groupBy ($ choice , $ keys [$ value ], $ value );
206
206
0 commit comments