authorizationHelper = $authorizationHelper; $this->translator = $translator; $this->paginatorFactory = $paginatorFactory; $this->requestStack = $requestStack; $this->thirdPartyACLAwareRepository = $thirdPartyACLAwareRepository; } protected function countEntities(string $action, Request $request, ?FilterOrderHelper $filterOrder = null): int { if (NULL === $filterOrder){ throw new \LogicException('filterOrder should not be null'); } return $this->thirdPartyACLAwareRepository->countThirdParties(ThirdPartyVoter::SHOW, $filterOrder->getQueryString()); } protected function getQueryResult(string $action, Request $request, int $totalItems, PaginatorInterface $paginator, ?FilterOrderHelper $filterOrder = null) { return $this->thirdPartyACLAwareRepository ->listThirdParties(ThirdPartyVoter::SHOW, $filterOrder->getQueryString(), ['name' => 'ASC'], $paginator->getItemsPerPage(), $paginator->getCurrentPageFirstItemNumber()); } protected function onPostCheckACL($action, Request $request, $entity): ?Response { if ('edit' === $action || 'view' === $action) { if ($entity->isChild()) { throw $this->createAccessDeniedException(); } } if ('new' === $action) { if (!$request->query->has('kind')) { return $this->render('@ChillThirdParty/ThirdParty/new_pick_kind.html.twig'); } else { $kind = $request->query->getAlpha('kind', ''); if (!(ThirdParty::KIND_COMPANY === $kind || ThirdParty::KIND_CONTACT === $kind)) { throw new BadRequestHttpException('This kind is not supported: '.$kind); } $entity->setKind($kind); } } return null; } protected function createFormFor(string $action, $entity, string $formClass = null, array $formOptions = []): FormInterface { if ('new' === $action) { return parent::createFormFor($action, $entity, $formClass, \array_merge( $formOptions, [ 'kind' => $this->requestStack->getCurrentRequest()->query->getAlpha('kind')] )); } elseif ('edit' === $action) { return parent::createFormFor($action, $entity, $formClass, \array_merge( $formOptions, [ 'kind' => $entity->getKind()] )); } return parent::createFormFor($action, $entity, $formClass, $formOptions); } protected function buildFilterOrderHelper(string $action, Request $request): ?FilterOrderHelper { return $this->getFilterOrderHelperFactory() ->create(self::class) ->addSearchBox(['name', 'company_name', 'acronym']) ->build(); } }