Skip to content

Commit fe981dc

Browse files
committed
Fix easyadmin url generator
1 parent 6777906 commit fe981dc

File tree

2 files changed

+27
-37
lines changed

2 files changed

+27
-37
lines changed

Controller/UserStatsController.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,17 @@
66
use App\Entity\User;
77
use DateTime;
88
use Doctrine\ORM\EntityManagerInterface;
9-
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
9+
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
1010
use FluffyFactory\Bundle\UserStatsBundle\Service\UserStatsService;
1111
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
12+
use Symfony\Component\HttpFoundation\RedirectResponse;
1213
use Symfony\Component\HttpFoundation\Request;
1314
use Symfony\Component\HttpFoundation\Response;
1415
use Symfony\Component\Routing\Annotation\Route;
1516
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1617

1718
class UserStatsController extends AbstractController
1819
{
19-
private $adminContextProvider;
20-
21-
public function __construct(AdminContextProvider $adminContextProvider)
22-
{
23-
$this->adminContextProvider = $adminContextProvider;
24-
}
25-
2620
/**
2721
* @Route("/user-stats/{id}", name="fluffy_user_stats")
2822
* @param User $user
@@ -49,17 +43,16 @@ public function userStats(User $user, Request $request, UserStatsService $userSt
4943
'page_views_year' => $pageViewYear,
5044
'avg_utilisation' => $avgUtilisation,
5145
'most_route_viewed' => $mostRouteViewed,
52-
'eaContext' => $request->query->get('eaContext'),
5346
]);
5447
}
5548

5649
/**
5750
* @Route("/remove-user-stats/{id}", name="fluffy_remove_user_stats")
5851
* @param User $user
5952
* @param UserStatsService $userStatsService
60-
* @return Response
53+
* @return RedirectResponse
6154
*/
62-
public function removeUserStats(Request $request, User $user, UserStatsService $userStatsService, EntityManagerInterface $entityManager, UrlGeneratorInterface $urlGenerator): Response
55+
public function removeUserStats(Request $request, User $user, UserStatsService $userStatsService, EntityManagerInterface $entityManager, AdminUrlGenerator $adminUrlGenerator): RedirectResponse
6356
{
6457
$user->setLastConnexion(null);
6558
$user->setLastVisited(null);
@@ -69,9 +62,6 @@ public function removeUserStats(Request $request, User $user, UserStatsService $
6962
$entityManager->persist($user);
7063
$entityManager->flush();
7164

72-
return $this->redirectToRoute('fluffy_user_stats', [
73-
'id' => $user->getId(),
74-
'eaContext' => $request->query->get('eaContext')
75-
]);
65+
return new RedirectResponse($adminUrlGenerator->setRoute('fluffy_user_stats', ['id' => $user->getId()])->generateUrl());
7666
}
7767
}

Resources/views/user-stats.html.twig

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -95,33 +95,33 @@
9595
<div class="col-sm-12">
9696
<div class="card">
9797
<div class="card-body">
98-
<table class="table table-bordered fluffy-user-stats-table" style="width: 100%">
99-
<thead>
98+
<table class="table table-bordered fluffy-user-stats-table" style="width: 100%">
99+
<thead>
100100
<tr>
101101
<th scope="col">{{ 'user.stats.table.head.date'|trans({}, 'UserStatsBundle') }}</th>
102102
<th scope="col">{{ 'user.stats.table.head.url'|trans({}, 'UserStatsBundle') }}</th>
103103
<th scope="col">{{ 'user.stats.table.head.route'|trans({}, 'UserStatsBundle') }}</th>
104104
<th class="no-sort" scope="col">{{ 'user.stats.table.head.link'|trans({}, 'UserStatsBundle') }}</th>
105105
</tr>
106-
</thead>
107-
<tbody>
108-
{% for page in page_views_year %}
109-
<tr>
110-
<td>{{ page.createdAt|format_datetime('medium', 'medium', locale=app.request.locale) }}</td>
111-
<td>
112-
{{ page.url|slice(0,50) }}{{ (page.url|length > 50) ? '...' }}
113-
</td>
114-
<td>{{ page.route }}</td>
115-
<td>
116-
<a class="btn btn-secondary" target="_blank" href="{{ page.url }}">
117-
<i class="fa fa-link"></i>
118-
</a>
119-
</td>
120-
</tr>
121-
{% endfor %}
122-
</tbody>
123-
</table>
124-
</div>
106+
</thead>
107+
<tbody>
108+
{% for page in page_views_year %}
109+
<tr>
110+
<td>{{ page.createdAt|format_datetime('medium', 'medium', locale=app.request.locale) }}</td>
111+
<td>
112+
{{ page.url|slice(0,50) }}{{ (page.url|length > 50) ? '...' }}
113+
</td>
114+
<td>{{ page.route }}</td>
115+
<td>
116+
<a class="btn btn-secondary" target="_blank" href="{{ page.url }}">
117+
<i class="fa fa-link"></i>
118+
</a>
119+
</td>
120+
</tr>
121+
{% endfor %}
122+
</tbody>
123+
</table>
124+
</div>
125125
</div>
126126
</div>
127127
</div>
@@ -138,7 +138,7 @@
138138
</div>
139139
<div class="modal-footer">
140140
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{{ 'action.cancel'|trans({}, 'EasyAdminBundle') }}</button>
141-
<a class="btn btn-danger" href="{{ path('fluffy_remove_user_stats', { id: user.id, eaContext: eaContext }) }}"><i class="fa fa-times me-2"></i>{{ 'actions.delete.stats'|trans({}, 'UserStatsBundle') }}</a>
141+
<a class="btn btn-danger" href="{{ ea_url().setRoute('fluffy_remove_user_stats', { id: user.id }) }}"><i class="fa fa-times me-2"></i>{{ 'actions.delete.stats'|trans({}, 'UserStatsBundle') }}</a>
142142
</div>
143143
</div>
144144
</div>

0 commit comments

Comments
 (0)