Skip to content

Commit 2abbe42

Browse files
committed
Refactor dashboard URLs in controllers
1 parent d58ba11 commit 2abbe42

2 files changed

Lines changed: 6 additions & 18 deletions

File tree

src/Controller/Dashboard/DashboardAccountController.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use CodedMonkey\Dirigent\Doctrine\Repository\UserRepository;
77
use CodedMonkey\Dirigent\Form\AccountFormType;
88
use CodedMonkey\Dirigent\Form\ChangePasswordFormType;
9-
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
109
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1110
use Symfony\Component\Form\FormError;
1211
use Symfony\Component\HttpFoundation\Request;
@@ -18,13 +17,6 @@
1817

1918
class DashboardAccountController extends AbstractController
2019
{
21-
public static function getSubscribedServices(): array
22-
{
23-
return array_merge(parent::getSubscribedServices(), [
24-
AdminUrlGenerator::class => AdminUrlGenerator::class,
25-
]);
26-
}
27-
2820
public function __construct(
2921
private readonly UserRepository $userRepository,
3022
private readonly UserPasswordHasherInterface $passwordHasher,
@@ -45,9 +37,7 @@ public function account(Request $request, #[CurrentUser] User $user): Response
4537

4638
$this->addFlash('success', 'Your account was successfully updated.');
4739

48-
$url = $this->container->get(AdminUrlGenerator::class)->setRoute('dashboard_account')->generateUrl();
49-
50-
return $this->redirect($url);
40+
return $this->redirectToRoute('dashboard_account');
5141
}
5242

5343
$passwordForm->handleRequest($request);
@@ -66,9 +56,7 @@ public function account(Request $request, #[CurrentUser] User $user): Response
6656

6757
$this->addFlash('success', 'Your password was successfully updated.');
6858

69-
$url = $this->container->get(AdminUrlGenerator::class)->setRoute('dashboard_account')->generateUrl();
70-
71-
return $this->redirect($url);
59+
return $this->redirectToRoute('dashboard_account');
7260
}
7361
}
7462

src/Controller/Dashboard/DashboardPackagesController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public function addVcsRepository(Request $request): Response
238238

239239
$this->messenger->dispatch(new UpdatePackage($package->getId()));
240240

241-
return $this->redirect($this->adminUrlGenerator->setRoute('dashboard_packages')->generateUrl());
241+
return $this->redirectToRoute('dashboard_packages');
242242
}
243243

244244
return $this->render('dashboard/packages/add_vcs.html.twig', [
@@ -263,7 +263,7 @@ public function edit(Request $request, string $packageName): Response
263263

264264
$this->messenger->dispatch(new UpdatePackage($package->getId()));
265265

266-
return $this->redirect($this->adminUrlGenerator->setRoute('dashboard_packages_info', ['packageName' => $package->getName()])->generateUrl());
266+
return $this->redirectToRoute('dashboard_packages_info', ['packageName' => $package->getName()]);
267267
}
268268

269269
return $this->render('dashboard/packages/package_edit.html.twig', [
@@ -280,7 +280,7 @@ public function update(string $packageName): Response
280280

281281
$this->messenger->dispatch(new UpdatePackage($package->getId(), forceRefresh: true));
282282

283-
return $this->redirect($this->adminUrlGenerator->setRoute('dashboard_packages_info', ['packageName' => $package->getName()])->generateUrl());
283+
return $this->redirectToRoute('dashboard_packages_info', ['packageName' => $package->getName()]);
284284
}
285285

286286
#[Route('/packages/{packageName}/delete', name: 'dashboard_packages_delete', requirements: ['packageName' => '[a-z0-9_.-]+/[a-z0-9_.-]+'])]
@@ -291,6 +291,6 @@ public function delete(string $packageName): Response
291291

292292
$this->packageRepository->remove($package, true);
293293

294-
return $this->redirect($this->adminUrlGenerator->setRoute('dashboard_packages')->generateUrl());
294+
return $this->redirectToRoute('dashboard_packages');
295295
}
296296
}

0 commit comments

Comments
 (0)