em = $entityManager; $this->translatorAdmin = $translatorAdmin; } public function overrideGlobalActions(?ActionCollection $actions): void { parent::overrideGlobalActions($actions); if ($actions) { $adminUrlGenerator = $this->get(AdminUrlGenerator::class); $creditControllerFqcn = $this->getControllerFqcnByInterface(CreditHistoryInterface::class); foreach ($actions as $action) { $url = $adminUrlGenerator ->setController($creditControllerFqcn) ->setAction(Action::NEW) ->set('userMerchantId', $this->getUserMerchant()->getId()) ->generateUrl(); $action->setLinkUrl($url); } } } 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(); $userMerchant = $this->get('em')->getRepository(UserMerchantInterface::class)->find( $request->get('userMerchantId') ); return $userMerchant; } public function configureActions(Actions $actions): Actions { $actions->disable(Action::DELETE, Action::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 { yield IdField::new('id')->hideOnForm(); yield ChoiceField::new('type')->setChoices( array( $this->translatorAdmin->transField( 'typeOptions.'.CreditHistoryModel::TYPE_CREDIT, 'CreditHistory' ) => CreditHistoryModel::TYPE_CREDIT, $this->translatorAdmin->transField( 'typeOptions.'.CreditHistoryModel::TYPE_DEBIT, 'CreditHistory' ) => CreditHistoryModel::TYPE_DEBIT, ) ); yield MoneyField::new('amount')->setCurrency('EUR'); yield DateField::new('paidAt'); yield ChoiceField::new('meanPayment')->setChoices( array( $this->translatorAdmin->transField( 'meanPaymentOptions.'.CreditHistoryModel::MEAN_PAYMENT_CASH, 'CreditHistory' ) => CreditHistoryModel::MEAN_PAYMENT_CASH, $this->translatorAdmin->transField( 'meanPaymentOptions.'.CreditHistoryModel::MEAN_PAYMENT_CHEQUE, 'CreditHistory' ) => CreditHistoryModel::MEAN_PAYMENT_CHEQUE, $this->translatorAdmin->transField( 'meanPaymentOptions.'.CreditHistoryModel::MEAN_PAYMENT_CREDIT, 'CreditHistory' ) => CreditHistoryModel::MEAN_PAYMENT_CREDIT, $this->translatorAdmin->transField( 'meanPaymentOptions.'.CreditHistoryModel::MEAN_PAYMENT_CREDIT_CARD, 'CreditHistory' ) => CreditHistoryModel::MEAN_PAYMENT_CREDIT_CARD, $this->translatorAdmin->transField( 'meanPaymentOptions.'.CreditHistoryModel::MEAN_PAYMENT_TRANSFER, 'CreditHistory' ) => CreditHistoryModel::MEAN_PAYMENT_TRANSFER, ) );; yield TextField::new('reference'); yield 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; } }