I can't find a way to redirect after saving or updating a record. it always redirects me to index(list of records). Easy admin symfony.
Thanks.
Tried using a subscriber or overriding the update entity method but no result
I can't find a way to redirect after saving or updating a record. it always redirects me to index(list of records). Easy admin symfony.
Thanks.
Tried using a subscriber or overriding the update entity method but no result
You can use method AbstractCrudController::getRedirectResponseAfterSave in your Crud Controller.
For example:
<?php
namespace App\Controller\Admin;
use App\Entity\Tag;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use Symfony\Component\HttpFoundation\RedirectResponse;
class TagCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Tag::class;
}
protected function getRedirectResponseAfterSave(AdminContext $context, string $action): RedirectResponse
{
/** @var Tag $tag */
$tag = $context->getEntity()->getInstance();
$adminUrlGenerator = $this->container->get(AdminUrlGenerator::class);
if ($tag->isPublic() && $tag->isEditable()) {
$url = $adminUrlGenerator
->setAction(Action::EDIT)
->setEntityId($tag->getId())
->generateUrl()
;
return $this->redirect($url);
}
if ($tag->isPublic()) {
return $this->redirect('https://google.com');
}
return parent::getRedirectResponseAfterSave($context, $action);
}
}