Skip to content

Commit 3c7fa23

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

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
*
2121
* @template T of object
2222
*
23-
* @method mixed getGroupBy() Return group_by option.
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.
25+
* @method mixed getGroupBy() Return group_by option.
2426
*/
2527
interface EntityAutocompleterInterface
2628
{
@@ -55,10 +57,8 @@ public function getValue(object $entity): mixed;
5557
/**
5658
* Returns the autocomplete result, usually the label as "text" and the value as "value".
5759
* May be used to expose extra options such as "disabled" so that tom-select's rendering may be customized.
58-
*
59-
* @param T $entity
6060
*/
61-
public function getResult(object $entity): array;
61+
/* public function getResult(object $entity): array; */
6262

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

0 commit comments

Comments
 (0)