Skip to content

Commit 74c226b

Browse files
committed
minor #7212 Fix more deprecations (javiereguiluz)
This PR was squashed before being merged into the 4.x branch. Discussion ---------- Fix more deprecations I still cannot tests full Symfony apps with Symfony 8.0 because many things are not ready yet ... but I installed Symfony 8 packages locally on EasyAdmin repo and saw some issues and deprecations. This PR fixes them. Commits ------- d590df3 Fix more deprecations
2 parents f718248 + d590df3 commit 74c226b

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
lines changed

src/Controller/AbstractCrudController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,11 @@ public function autocomplete(AdminContext $context): JsonResponse
471471
{
472472
$queryBuilder = $this->createIndexQueryBuilder($context->getSearch(), $context->getEntity(), FieldCollection::new([]), FilterCollection::new());
473473

474-
$autocompleteContext = $context->getRequest()->get(AssociationField::PARAM_AUTOCOMPLETE_CONTEXT);
474+
$autocompleteContext = $context->getRequest()->query->all(AssociationField::PARAM_AUTOCOMPLETE_CONTEXT);
475475

476+
$crudControllerFqcn = $autocompleteContext[EA::CRUD_CONTROLLER_FQCN] ?? $context->getRequest()->attributes->get(EA::CRUD_CONTROLLER_FQCN) ?? $context->getRequest()->query->get(EA::CRUD_CONTROLLER_FQCN);
476477
/** @var CrudControllerInterface $controller */
477-
$controller = $this->container->get(ControllerFactory::class)->getCrudControllerInstance($autocompleteContext[EA::CRUD_CONTROLLER_FQCN] ?? $context->getRequest()->get(EA::CRUD_CONTROLLER_FQCN), Action::INDEX, $context->getRequest());
478+
$controller = $this->container->get(ControllerFactory::class)->getCrudControllerInstance($crudControllerFqcn, Action::INDEX, $context->getRequest());
478479
/** @var FieldDto|null $field */
479480
$field = FieldCollection::new($controller->configureFields($autocompleteContext['originatingPage']))->getByProperty($autocompleteContext['propertyName']);
480481
/** @var \Closure|null $queryBuilderCallable */

src/Controller/AbstractDashboardController.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,19 @@
1515
use EasyCorp\Bundle\EasyAdminBundle\Security\Permission;
1616
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1717
use Symfony\Component\HttpFoundation\Response;
18-
use Symfony\Component\Routing\Annotation\Route;
1918
use Symfony\Component\Security\Core\User\UserInterface;
2019
use Symfony\Component\Security\Http\Logout\LogoutUrlGenerator;
2120
use function Symfony\Component\Translation\t;
2221

22+
// needed for Symfony 5.4 - 8.0 compatibility (Atribute doesn't exist in 5.4 and
23+
// Annotation doesn't exist in 8.0; both exist in the other versions)
24+
if (!class_exists(Route::class)) {
25+
// @phpstan-ignore-next-line class.notFound
26+
class_alias(\Symfony\Component\Routing\Annotation\Route::class, Route::class);
27+
}
28+
29+
use Symfony\Component\Routing\Attribute\Route;
30+
2331
/**
2432
* This class is useful to extend your dashboard from it instead of implementing
2533
* the interface.

src/Router/AdminRouteGenerator.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,11 @@ private function getDashboardsRouteConfig(): array
567567

568568
$routeAttribute = $attributes[0]->newInstance();
569569
$config[$reflectionClass->getName()] = [
570-
'routeName' => $routeAttribute->getName(),
571-
'routePath' => rtrim($routeAttribute->getPath(), '/'),
570+
// Symfony 8 removed the getName() and getPath() methods in favor of public properties
571+
/** @phpstan-ignore-next-line */
572+
'routeName' => method_exists($routeAttribute, 'getName') ? $routeAttribute->getName() : $routeAttribute->name,
573+
/** @phpstan-ignore-next-line */
574+
'routePath' => rtrim(method_exists($routeAttribute, 'getPath') ? $routeAttribute->getPath() : $routeAttribute->path, '/'),
572575
];
573576
}
574577

src/Translation/TranslatableChoiceMessage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ public function trans(TranslatorInterface $translator, ?string $locale = null):
3434
public function __toString(): string
3535
{
3636
if (null !== $this->cssClass) {
37-
return sprintf('<span class="%s">%s</span>', $this->cssClass, $this->message);
37+
return sprintf('<span class="%s">%s</span>', $this->cssClass, $this->message->getMessage());
3838
}
3939

40-
return (string) $this->message;
40+
return $this->message->getMessage();
4141
}
4242
}

src/Twig/EasyAdminTwigExtension.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ public function applyFilterIfExists(Environment $environment, mixed $value, stri
167167
}
168168

169169
if (\is_array($callback) && 2 === \count($callback)) {
170-
$callback = [$environment->getRuntime(array_shift($callback)), array_pop($callback)];
170+
/** @var class-string $runtimeClass */
171+
$runtimeClass = array_shift($callback);
172+
$callback = [$environment->getRuntime($runtimeClass), array_pop($callback)];
171173
if (!\is_callable($callback)) {
172174
throw new RuntimeError(sprintf('Unable to load runtime for filter: "%s"', $filterName));
173175
}
@@ -257,7 +259,9 @@ public function callFunctionIfExists(Environment $environment, string $functionN
257259
}
258260

259261
if (\is_array($callback) && 2 === \count($callback)) {
260-
$callback = [$environment->getRuntime(array_shift($callback)), array_pop($callback)];
262+
/** @var class-string $runtimeClass */
263+
$runtimeClass = array_shift($callback);
264+
$callback = [$environment->getRuntime($runtimeClass), array_pop($callback)];
261265
if (!\is_callable($callback)) {
262266
throw new RuntimeError(sprintf('Unable to load runtime for function: "%s"', $functionName));
263267
}

0 commit comments

Comments
 (0)