From d4379cef6ab4857367a9a4ddcdeba748663102d8 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 1 Oct 2025 10:10:34 +0200 Subject: [PATCH] Fix visibility of EntityManager parameter in child classes --- .../Controller/EntityPersonCRUDController.php | 26 +++++++------------ .../OneToOneEntityPersonCRUDController.php | 5 ++-- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/CRUD/Controller/EntityPersonCRUDController.php b/src/Bundle/ChillPersonBundle/CRUD/Controller/EntityPersonCRUDController.php index 6a4bcbb56..b54578595 100644 --- a/src/Bundle/ChillPersonBundle/CRUD/Controller/EntityPersonCRUDController.php +++ b/src/Bundle/ChillPersonBundle/CRUD/Controller/EntityPersonCRUDController.php @@ -12,8 +12,10 @@ declare(strict_types=1); namespace Chill\PersonBundle\CRUD\Controller; use Chill\MainBundle\CRUD\Controller\CRUDController; +use Chill\MainBundle\CRUD\Controller\string; use Chill\PersonBundle\Entity\Person; use Doctrine\ORM\QueryBuilder; +use Doctrine\Persistence\ManagerRegistry; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -23,9 +25,9 @@ use Symfony\Component\HttpFoundation\Response; */ class EntityPersonCRUDController extends CRUDController { - public function __construct(protected readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {} + public function __construct(protected ManagerRegistry $managerRegistry) {} - protected function generateTemplateParameter(string $action, mixed $entity, Request $request, array $defaultTemplateParameters = []) + protected function generateTemplateParameter(string $action, mixed $entity, Request $request, array $defaultTemplateParameters = []): array { $templateParameters = parent::generateTemplateParameter($action, $entity, $request, $defaultTemplateParameters); @@ -36,20 +38,15 @@ class EntityPersonCRUDController extends CRUDController /** * Override the base method to add a filtering step to a person. - * - * @return QueryBuilder */ - protected function buildQueryEntities(string $action, Request $request): \Doctrine\ORM\QueryBuilder + protected function buildQueryEntities(string $action, Request $request): QueryBuilder { $qb = parent::buildQueryEntities($action, $request); return $this->filterQueryEntitiesByPerson($action, $qb, $request); } - /** - * @param \Chill\MainBundle\CRUD\Controller\string|string $action - */ - protected function createEntity($action, Request $request): object + protected function createEntity(string $action, Request $request): object { $entity = parent::createEntity($action, $request); @@ -63,9 +60,10 @@ class EntityPersonCRUDController extends CRUDController /** * Add a where clause to the buildQuery. * - * @param \Chill\PersonBundle\CRUD\Controller\QueryBuilder $qb - * - * @return \Chill\PersonBundle\CRUD\Controller\QueryBuilder + * @param string $action + * @param QueryBuilder $qb + * @param Request $request + * @return QueryBuilder */ protected function filterQueryEntitiesByPerson(string $action, QueryBuilder $qb, Request $request): QueryBuilder { @@ -137,10 +135,6 @@ class EntityPersonCRUDController extends CRUDController 'save-and-new' => $this->redirectToRoute('chill_crud_'.$this->getCrudName().'_new', [ 'person_id' => $this->getPerson($request)->getId(), ]), - 'new' => $this->redirectToRoute('chill_crud_'.$this->getCrudName().'_view', [ - 'id' => $entity->getId(), - 'person_id' => $this->getPerson($request)->getId(), - ]), default => $this->redirectToRoute('chill_crud_'.$this->getCrudName().'_view', [ 'id' => $entity->getId(), 'person_id' => $this->getPerson($request)->getId(), diff --git a/src/Bundle/ChillPersonBundle/CRUD/Controller/OneToOneEntityPersonCRUDController.php b/src/Bundle/ChillPersonBundle/CRUD/Controller/OneToOneEntityPersonCRUDController.php index 55b788cc2..c7e578955 100644 --- a/src/Bundle/ChillPersonBundle/CRUD/Controller/OneToOneEntityPersonCRUDController.php +++ b/src/Bundle/ChillPersonBundle/CRUD/Controller/OneToOneEntityPersonCRUDController.php @@ -13,6 +13,7 @@ namespace Chill\PersonBundle\CRUD\Controller; use Chill\MainBundle\CRUD\Controller\CRUDController; use Chill\PersonBundle\Entity\Person; +use Doctrine\Persistence\ManagerRegistry; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; @@ -20,7 +21,7 @@ use Symfony\Component\HttpFoundation\Response; class OneToOneEntityPersonCRUDController extends CRUDController { - public function __construct(private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {} + public function __construct(protected ManagerRegistry $managerRegistry) {} protected function generateRedirectOnCreateRoute($action, Request $request, $entity): string { @@ -67,7 +68,7 @@ class OneToOneEntityPersonCRUDController extends CRUDController return null; } - protected function onPreFlush(string $action, $entity, FormInterface $form, Request $request) + protected function onPreFlush(string $action, $entity, FormInterface $form, Request $request): void { $this->managerRegistry->getManager()->persist($entity); }