@@ -73,7 +73,7 @@ public function fetchResults(EntityAutocompleterInterface $autocompleter, string
7373
7474 if (!method_exists ($ autocompleter , 'getGroupBy ' ) || null === $ groupBy = $ autocompleter ->getGroupBy ()) {
7575 foreach ($ paginator as $ entity ) {
76- $ results [] = $ autocompleter-> getResult ( $ entity );
76+ $ results [] = self :: getAutocompleterResult ( $ autocompleter, $ entity );
7777 }
7878
7979 return new AutocompleteResults ($ results , $ hasNextPage );
@@ -101,7 +101,7 @@ public function fetchResults(EntityAutocompleterInterface $autocompleter, string
101101 $ optgroupLabels = [];
102102
103103 foreach ($ paginator as $ entity ) {
104- $ result = $ autocompleter-> getResult ( $ entity );
104+ $ result = self :: getAutocompleterResult ( $ autocompleter, $ entity );
105105
106106 $ groupLabels = $ groupBy ($ entity , $ result ['value ' ], $ result ['text ' ]);
107107
@@ -118,4 +118,19 @@ public function fetchResults(EntityAutocompleterInterface $autocompleter, string
118118
119119 return new AutocompleteResults ($ results , $ hasNextPage , $ optgroups );
120120 }
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+ }
121136}
0 commit comments