Skip to content

Commit b66fb61

Browse files
committed
[Autocomplete] Prevent BC break by commenting the EntityAutocompleterInterface::getResult() method until next major version
1 parent 220bd68 commit b66fb61

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/Autocomplete/src/AutocompleteResultsExecutor.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/Autocomplete/src/EntityAutocompleterInterface.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
*
2121
* @template T of object
2222
*
23+
* @method array getResults(object $entity) Returns the autocomplete result, usually the label as "text" and the value as "value".
24+
* May be used to expose extra options such as "disabled" so that tom-select's rendering may be customized.
2325
* @method mixed getGroupBy() Return group_by option.
2426
*/
2527
interface EntityAutocompleterInterface
@@ -57,8 +59,10 @@ public function getValue(object $entity): mixed;
5759
* May be used to expose extra options such as "disabled" so that tom-select's rendering may be customized.
5860
*
5961
* @param T $entity
62+
*
63+
* @return array<string, mixed>
6064
*/
61-
public function getResult(object $entity): array;
65+
/* public function getResult(object $entity): array; */
6266

6367
/**
6468
* Return true if access should be granted to the autocomplete results for the current user.

0 commit comments

Comments
 (0)