33
44namespace Arkounay \Bundle \QuickAdminGeneratorBundle \Controller ;
55
6+ use Arkounay \Bundle \QuickAdminGeneratorBundle \Extension \EntityService ;
67use Arkounay \Bundle \QuickAdminGeneratorBundle \Extension \FieldService ;
78use Arkounay \Bundle \QuickAdminGeneratorBundle \Extension \RouteExtension ;
89use Arkounay \Bundle \QuickAdminGeneratorBundle \Extension \TwigLoaderService ;
@@ -56,6 +57,7 @@ abstract class Crud extends AbstractController
5657 protected TranslatorInterface $ translator ;
5758 protected TwigLoaderService $ twigLoader ;
5859 protected QagExtensionRuntime $ qagExtensionRuntime ;
60+ protected EntityService $ entityService ;
5961
6062 /** @var EntityRepository<T> */
6163 protected EntityRepository $ repository ;
@@ -88,7 +90,8 @@ public function setInternalDependencies(
8890 TranslatorInterface $ translator ,
8991 TwigLoaderService $ twigLoader ,
9092 SluggerInterface $ slugger ,
91- QagExtensionRuntime $ qagExtensionRuntime
93+ QagExtensionRuntime $ qagExtensionRuntime ,
94+ EntityService $ entityService
9295 ): void {
9396 $ this ->em = $ em ;
9497 $ this ->fieldService = $ fieldService ;
@@ -100,6 +103,7 @@ public function setInternalDependencies(
100103 $ this ->repository = $ em ->getRepository ($ this ->getEntity ());
101104 $ this ->slugger = $ slugger ;
102105 $ this ->qagExtensionRuntime = $ qagExtensionRuntime ;
106+ $ this ->entityService = $ entityService ;
103107 }
104108
105109 /**
@@ -323,7 +327,7 @@ public function toggleBooleanPostAction(Request $request, $entity): Response
323327 if (!$ this ->isEditableBoolean ($ entity )) {
324328 throw $ this ->createAccessDeniedException ("Entity {$ this ->getEntity ()} cannot be edited (boolean). " );
325329 }
326-
330+
327331 $ index = $ request ->request ->get ('index ' );
328332 $ value = $ request ->request ->getBoolean ('checked ' );
329333 $ propertyAccessor = PropertyAccess::createPropertyAccessor ();
@@ -637,7 +641,7 @@ protected function updateEntity($entity, bool $creation): void
637641 if ($ event ->isPropagationStopped ()) {
638642 return ;
639643 }
640- $ this ->addFlash ('highlighted_row_id ' , $ entity -> getId ());
644+ $ this ->addFlash ('highlighted_row_id ' , $ this -> entityService -> getId ($ entity ));
641645 }
642646
643647 /**
@@ -1090,7 +1094,7 @@ protected function entityIsInList($entity): bool
10901094 {
10911095 return $ this ->getListQueryBuilder ()
10921096 ->andWhere ('e.id = :id ' )
1093- ->setParameter ('id ' , $ entity -> getId ())
1097+ ->setParameter ('id ' , $ this -> entityService -> getId ($ entity ))
10941098 ->getQuery ()
10951099 ->getOneOrNullResult () !== null ;
10961100 }
@@ -1158,7 +1162,7 @@ public function checkSecurity(string $action, $entity = null): void
11581162 throw $ this ->createAccessDeniedException ("Entity {$ this ->getEntity ()} cannot be edited. " );
11591163 }
11601164 if ($ this ->hasQuickListQueryBuilderSecurity () && !$ this ->entityIsInList ($ entity )) {
1161- throw $ this ->createAccessDeniedException ("Entity {$ this ->getEntity ()} # {$ entity -> getId ()} is filtered out. " );
1165+ throw $ this ->createAccessDeniedException ("Entity {$ this ->getEntity ()} # {$ this -> entityService -> getId ($ entity )} is filtered out. " );
11621166 }
11631167 if ($ entity === null ) {
11641168 throw $ this ->createNotFoundException ("No {$ this ->getNameSentence ()} found with id # {$ this ->request ->attributes ->get ('id ' )}" );
@@ -1174,15 +1178,15 @@ public function checkSecurity(string $action, $entity = null): void
11741178 throw $ this ->createAccessDeniedException ("Entity {$ this ->getEntity ()} is not removable. " );
11751179 }
11761180 if ($ this ->hasQuickListQueryBuilderSecurity () && !$ this ->entityIsInList ($ entity )) {
1177- throw $ this ->createAccessDeniedException ("Entity {$ this ->getEntity ()} # {$ entity -> getId ()} is filtered out. " );
1181+ throw $ this ->createAccessDeniedException ("Entity {$ this ->getEntity ()} # {$ this -> entityService -> getId ($ entity )} is filtered out. " );
11781182 }
11791183 break ;
11801184 case 'view ' :
11811185 if (!$ this ->isViewable ($ entity )) {
11821186 throw $ this ->createAccessDeniedException ("Entity {$ this ->getEntity ()} cannot be viewed. " );
11831187 }
11841188 if ($ this ->hasQuickListQueryBuilderSecurity () && !$ this ->entityIsInList ($ entity )) {
1185- throw $ this ->createAccessDeniedException ("Entity {$ this ->getEntity ()} # {$ entity -> getId ()} is filtered out. " );
1189+ throw $ this ->createAccessDeniedException ("Entity {$ this ->getEntity ()} # {$ this -> entityService -> getId ($ entity )} is filtered out. " );
11861190 }
11871191 if ($ entity === null ) {
11881192 throw $ this ->createNotFoundException ("No {$ this ->getName ()} found with id # {$ this ->request ->attributes ->get ('id ' )}" );
@@ -1193,7 +1197,7 @@ public function checkSecurity(string $action, $entity = null): void
11931197 throw $ this ->createAccessDeniedException ("Entity {$ this ->getEntity ()} cannot be edited. " );
11941198 }
11951199 if ($ this ->hasQuickListQueryBuilderSecurity () && !$ this ->entityIsInList ($ entity )) {
1196- throw $ this ->createAccessDeniedException ("Entity {$ this ->getEntity ()} # {$ entity -> getId ()} is filtered out. " );
1200+ throw $ this ->createAccessDeniedException ("Entity {$ this ->getEntity ()} # {$ this -> entityService -> getId ($ entity )} is filtered out. " );
11971201 }
11981202 break ;
11991203 }
@@ -1202,4 +1206,4 @@ public function checkSecurity(string $action, $entity = null): void
12021206 $ this ->eventDispatcher ->dispatch ($ event , 'qag.events.security ' );
12031207 }
12041208
1205- }
1209+ }
0 commit comments