get(AdminUrlGenerator::class); $creditControllerFqcn = $this->getControllerFqcnByInterface(CreditHistoryInterface::class); foreach ($actions as $action) { $url = $adminUrlGenerator ->setController($creditControllerFqcn) ->setAction(ActionDefinition::NEW) ->set('userMerchantId', $this->getUserMerchant()->getId()) ->generateUrl(); $action->setLinkUrl($url); } } } public function createEntity(string $entityFqcn) { return $this->get(CreditHistoryContainer::class)->getFactory()->create(); } public function persistEntity(EntityManagerInterface $entityManager, $entityInstance): void { $entityInstance->setUserMerchant($this->getUserMerchant()); parent::persistEntity($entityManager, $entityInstance); // TODO: Change the autogenerated stub } protected function getUserMerchant(): UserMerchantInterface { $request = $this->get(AdminContextProvider::class)->getContext()->getRequest(); return $this->get(UserMerchantContainer::class)->getStore()->getOneById( $request->get('userMerchantId') ); } public function configureActions(Actions $actions): Actions { $actions->disable(ActionDefinition::DELETE, ActionDefinition::EDIT); return parent::configureActions($actions); // TODO: Change the autogenerated stub } public function configureCrud(Crud $crud): Crud { $crud->overrideTemplate('crud/index', '@LcCaracole/admin/credit/index_credithistory.html.twig'); return $crud; } public function configureFields(string $pageName): iterable { $translatorAdmin = $this->get(TranslatorAdmin::class); return [ IdField::new('id')->hideOnForm(), // @TODO : transChoices ChoiceField::new('type')->setChoices( array( $translatorAdmin->transField( 'typeOptions.' . CreditHistoryModel::TYPE_CREDIT, 'CreditHistory' ) => CreditHistoryModel::TYPE_CREDIT, $translatorAdmin->transField( 'typeOptions.' . CreditHistoryModel::TYPE_DEBIT, 'CreditHistory' ) => CreditHistoryModel::TYPE_DEBIT, ) ), MoneyField::new('amount')->setCurrency('EUR'), DateField::new('paidAt'), // @TODO : transChoices ChoiceField::new('meanPayment')->setChoices( array( $translatorAdmin->transField( 'meanPaymentOptions.' . OrderPaymentModel::MEAN_PAYMENT_CASH, 'CreditHistory' ) => OrderPaymentModel::MEAN_PAYMENT_CASH, $translatorAdmin->transField( 'meanPaymentOptions.' . OrderPaymentModel::MEAN_PAYMENT_CHEQUE, 'CreditHistory' ) => OrderPaymentModel::MEAN_PAYMENT_CHEQUE, $translatorAdmin->transField( 'meanPaymentOptions.' . OrderPaymentModel::MEAN_PAYMENT_CREDIT, 'CreditHistory' ) => OrderPaymentModel::MEAN_PAYMENT_CREDIT, $translatorAdmin->transField( 'meanPaymentOptions.' . OrderPaymentModel::MEAN_PAYMENT_CREDIT_CARD, 'CreditHistory' ) => OrderPaymentModel::MEAN_PAYMENT_CREDIT_CARD, $translatorAdmin->transField( 'meanPaymentOptions.' . OrderPaymentModel::MEAN_PAYMENT_TRANSFER, 'CreditHistory' ) => OrderPaymentModel::MEAN_PAYMENT_TRANSFER, ) ), TextField::new('reference'), TextField::new('comment'), ]; } public function createIndexQueryBuilder( SearchDto $searchDto, EntityDto $entityDto, FieldCollection $fields, FilterCollection $filters ): QueryBuilder { $queryBuilder = parent::createIndexQueryBuilder( $searchDto, $entityDto, $fields, $filters ); $queryBuilder->andWhere('entity.userMerchant = :userMerchant'); $queryBuilder->setParameter('userMerchant', $searchDto->getRequest()->get('userMerchantId')); return $queryBuilder; } }