get(CreditHistoryContainer::class)->getRepositoryQuery(); } 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(ActionDefinition::NEW) ->set('userMerchantId', $this->getUserMerchant()->getId()) ->generateUrl(); $action->setLinkUrl($url); } } } public function createEntity(string $entityFqcn) { return $this->get(CreditHistoryContainer::class)->getFactory()->createBase($this->getUserMerchant()); } 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 = parent::configureActions($actions); $actions->disable(ActionDefinition::DELETE, ActionDefinition::EDIT, ActionDefinition::DUPLICATE); return $actions; } public function persistEntity(EntityManagerInterface $entityManager, $entityInstance): void { if ($this->get(CreditHistoryContainer::class)->getBuilder()->save($entityInstance)) { $this->addFlashTranslator('success', 'saveCreditHistory'); } else { $this->addFlashTranslator('error', 'saveCreditHistory'); } } public function configureCrud(Crud $crud): Crud { $crud->overrideTemplate('crud/index', '@LcCaracole/admin/credit/index_credithistory.html.twig'); return $crud; } public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore { $responseParameters = parent::configureResponseParameters($responseParameters); $responseParameters->set('user_merchant', $this->getUserMerchant()); return $responseParameters; } public function configureFields(string $pageName): iterable { return $this->getCreditHistoryContainer()->getFieldDefinition()->getFields($pageName); } public function createIndexRepositoryQuery( SearchDto $searchDto, EntityDto $entityDto, FieldCollection $fields, FilterCollection $filters ): RepositoryQueryInterface { $repositoryQuery = parent::createIndexRepositoryQuery( $searchDto, $entityDto, $fields, $filters ); $repositoryQuery->filterByUserMerchant($this->getUserMerchant()); return $repositoryQuery; } }