@@ -73,10 +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 [] = [
77
- 'value ' => $ autocompleter ->getValue ($ entity ),
78
- 'text ' => $ autocompleter ->getLabel ($ entity ),
79
- ];
76
+ $ results [] = $ this ->formatResult ($ autocompleter , $ entity );
80
77
}
81
78
82
79
return new AutocompleteResults ($ results , $ hasNextPage );
@@ -104,10 +101,7 @@ public function fetchResults(EntityAutocompleterInterface $autocompleter, string
104
101
$ optgroupLabels = [];
105
102
106
103
foreach ($ paginator as $ entity ) {
107
- $ result = [
108
- 'value ' => $ autocompleter ->getValue ($ entity ),
109
- 'text ' => $ autocompleter ->getLabel ($ entity ),
110
- ];
104
+ $ result = $ this ->formatResult ($ autocompleter , $ entity );
111
105
112
106
$ groupLabels = $ groupBy ($ entity , $ result ['value ' ], $ result ['text ' ]);
113
107
@@ -124,4 +118,21 @@ public function fetchResults(EntityAutocompleterInterface $autocompleter, string
124
118
125
119
return new AutocompleteResults ($ results , $ hasNextPage , $ optgroups );
126
120
}
121
+
122
+ /**
123
+ * @return array<string, mixed>
124
+ */
125
+ private function formatResult (EntityAutocompleterInterface $ autocompleter , object $ entity ): array
126
+ {
127
+ $ attributes = [];
128
+ if (method_exists ($ autocompleter , 'getAttributes ' )) {
129
+ $ attributes = $ autocompleter ->getAttributes ($ entity );
130
+ }
131
+
132
+ return [
133
+ ...$ attributes ,
134
+ 'value ' => $ autocompleter ->getValue ($ entity ),
135
+ 'text ' => $ autocompleter ->getLabel ($ entity ),
136
+ ];
137
+ }
127
138
}
0 commit comments