EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

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

Open teklakct opened this issue 5 months ago • 1 comments

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 avatar Sep 21 '24 22:09 teklakct