@@ -73,7 +73,7 @@ public function fetchResults(EntityAutocompleterInterface $autocompleter, string
73
73
74
74
if (!method_exists ($ autocompleter , 'getGroupBy ' ) || null === $ groupBy = $ autocompleter ->getGroupBy ()) {
75
75
foreach ($ paginator as $ entity ) {
76
- $ results [] = $ autocompleter-> getResult ( $ entity );
76
+ $ results [] = self :: getAutocompleterResult ( $ autocompleter, $ entity );
77
77
}
78
78
79
79
return new AutocompleteResults ($ results , $ hasNextPage );
@@ -101,7 +101,7 @@ public function fetchResults(EntityAutocompleterInterface $autocompleter, string
101
101
$ optgroupLabels = [];
102
102
103
103
foreach ($ paginator as $ entity ) {
104
- $ result = $ autocompleter-> getResult ( $ entity );
104
+ $ result = self :: getAutocompleterResult ( $ autocompleter, $ entity );
105
105
106
106
$ groupLabels = $ groupBy ($ entity , $ result ['value ' ], $ result ['text ' ]);
107
107
@@ -118,4 +118,19 @@ public function fetchResults(EntityAutocompleterInterface $autocompleter, string
118
118
119
119
return new AutocompleteResults ($ results , $ hasNextPage , $ optgroups );
120
120
}
121
+
122
+ /**
123
+ * @return array<string, mixed>
124
+ */
125
+ private static function getAutocompleterResult (EntityAutocompleterInterface $ autocompleter , object $ entity ): array
126
+ {
127
+ if (method_exists ($ autocompleter , 'getResult ' )) {
128
+ return $ autocompleter ->getResult ($ entity );
129
+ }
130
+
131
+ return [
132
+ 'value ' => $ autocompleter ->getValue ($ entity ),
133
+ 'text ' => $ autocompleter ->getLabel ($ entity ),
134
+ ];
135
+ }
121
136
}
0 commit comments