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

AdminContext::getEntity() return null (instead of EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto) #6505

Open
damien-louis opened this issue Nov 4, 2024 · 3 comments

Comments

@damien-louis
Copy link

Describe the bug
The bug appear with v4.14. I'm face with it in two contexts.

  1. On an EventSubcriber :
<?php
...
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeCrudActionEvent;
...
class DocumentController extends AbstractCrudController implements EventSubscriberInterface
...
    public static function getSubscribedEvents(): array
    {
        return [
            BeforeCrudActionEvent::class => 'onBeforeCrudActionEvent',
        ];
    }

    public function onBeforeCrudActionEvent(BeforeCrudActionEvent $event): void
    {
        $context = $event->getAdminContext();
        $entityInstance = $context?->getEntity()->getInstance();
    }

Give me this error:
EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext::getEntity(): Return value must be of type EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto, null returned

  1. On a specific controller to create entity.

On my CrudController:

    public function configureActions(Actions $actions): Actions
    {
        $customNewAction = Action::new('customNew', 'Add New')
            ->linkToRoute('backoffice_user_create')->addCssClass('btn btn-primary')->createAsGlobalAction()
        ;

        return $actions
            ->add(Crud::PAGE_INDEX, Action::DETAIL)
            ->add(Crud::PAGE_INDEX, $customNewAction)
            ->disable(Action::DELETE, Action::NEW, Action::EDIT)
        ;
    }

When I visit link generated (/admin?routeName=backoffice_user_create), same error, located in vendor/easycorp/easyadmin-bundle/src/Controller/AbstractCrudController.php:292:

EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext::getEntity(): Return value must be of type EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto, null returned

To Reproduce
Easy ton reproduce with first example above.

@damien-louis
Copy link
Author

Bug still here with v4.14.2

@damien-louis
Copy link
Author

damien-louis commented Nov 6, 2024

Ok, I find a way to bypass the bug.

My dashboard route is:

#[Route('/admin', name: 'backoffice')]

And the bug appears if by route in custom controller start by admin

#[Route('/admin/user/new', name: 'backoffice_user_create')]

With:

#[Route('/another/user/new', name: 'backoffice_user_create')]

or

#[Route('name: 'backoffice_user_create')]

it's ok

And I don't have problem with custom edit routes (because entity is defined probably)

@damien-louis
Copy link
Author

Nobody else have this problem?

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