Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

method to get DashboardControllerInstance in AdminContext or using Crud actions in Symfony standard controller #6453

Open
teklakct opened this issue Sep 21, 2024 · 1 comment

Comments

@teklakct
Copy link
Contributor

TLDR;

Is there any reason why there is no method to get DashboardControllerInstance in AdminContext? Currently, we can get the Fqcn of dashboard controller, and then use the ControllerFactory but IMO it is way to much.

Short description of what this feature will allow to do:
I need to create a custom "DETAIL" page for my entity. I want to use actions that are defined in CrudController but in the template that is rendered by the normal Symfony controller.
My idea is to call configureActions from CrudController inside my normal Symfony controller.

What I am missing right now is the easy way of receiving the default Actions config.
Ok, I can copy the configureActions from AbstractDashboardController but it's quite ugly solution. My current idea is to call configureActions on my target CrudController, but the hardest part is to get the instance of the dashboard controller.

Below I show some ugly code, how it could be achieved.

Example of how to use this feature

use App\Controller\Admin\CustomerCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class SomeController extends AbstractController
{
    public function someMethod(AdminContext $context, CustomerCrudController $customerCrudController)
    {
        // ...
       $dashboardController = $context->getDashboardController():
       $defaultActionConfig = $dashboardController->configureActions();
       $actionConfigDto = $customerCrudController->configureActions($defaultActionConfig)->getAsDto(Crud::PAGE_DETAIL);

        return $this->render('admin/business_stats/customer.html.twig', [
            'actions' => $actionConfigDto->getActions(),
            'data' => $this->businessStatsCalculator->getCustomerStats($customer),
        ]);
    }
}

and in the template

{# templates/admin/business_stats/index.html.twig #}
{% extends '@EasyAdmin/page/content.html.twig' %}

   //...

{% block page_actions %}
    {% for action in actions %}
        {{ include(action.templatePath, { action: action }, with_context = false) }}
    {% endfor %}
{% endblock %}

  //...
@teklakct
Copy link
Contributor Author

Also, it might be good to add an option to pass a custom page name to ActionFactory::processEntityActions

- public function processEntityActions(EntityDto $entityDto, ActionConfigDto $actionsDto, ?string pageName = null): void
- public function processEntityActions(EntityDto $entityDto, ActionConfigDto $actionsDto): void
    {
+       $currentPage = $pageName ?: $this->adminContextProvider->getContext()->getCrud()->getCurrentPage();    
-        $currentPage = $this->adminContextProvider->getContext()->getCrud()->getCurrentPage();
        //..

The there will be an option to define and use the same template and actions in standard Symfony controllers

@teklakct teklakct changed the title method to get DashboardControllerInstance in AdminContext method to get DashboardControllerInstance in AdminContext or using Crud actions in Symfony standard controller Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant