EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

Easyadmin 4: Dashboard Controller don`t list the Menü

Open sellrock-de opened this issue 4 years ago • 6 comments

I installed the Easyadmin 4.

Inside my DashboardController I have like Easyadmin 3 the same MenüItems. But Easyadmin Shows me only a "Welcome" Page and ignore my Menu.

namespace App\Controller\Admin;

use App\Entity\User (some more);
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class DashboardController extends AbstractDashboardController
{
    #[Route(path: '/admin', name: 'admin')]
    public function index(): Response
    {
        return parent::index();
    }

    public function configureDashboard(): Dashboard
    {
        return Dashboard::new()
            ->setTitle('Skinpull Symfony');
    }
    
    public function configureMenuItems(): iterable
    {
        yield MenuItem::linktoDashboard('Dashboard', 'fa fa-home');
        
        MenuItem::subMenu('Account', 'fa fa-article')->setSubItems([
            yield MenuItem::linkToCrud('User', 'fas fa-list', User::class),
        ]);
        
        MenuItem::subMenu('Settings', 'fa fa-article')->setSubItems([
            yield MenuItem::linkToCrud('Mail', 'fas fa-list', Mail::class),
            yield MenuItem::linkToCrud('Uploads', 'fas fa-list', Upload::class),
        ]);
       }
  }

Any Issue here or you changed the Working of them?

image

sellrock-de avatar Jan 20 '22 10:01 sellrock-de

The real problem is that you never customized the Dashboard page, so you always showed the "Welcome Page". Now that the welcome Page has changed, you see this issue.

The solution is to customize the Dashboard. The Dashboard controller generated automatically with the command make:admin:dashboard shows the following options:

        // Option 1. You can make your dashboard redirect to some common page of your backend
        //
        // $adminUrlGenerator = $this->container->get(AdminUrlGenerator::class);
        // return $this->redirect($adminUrlGenerator->setController(OneOfYourCrudController::class)->generateUrl());

        // Option 2. You can make your dashboard redirect to different pages depending on the user
        //
        // if ('jane' === $this->getUser()->getUsername()) {
        //     return $this->redirect('...');
        // }

        // Option 3. You can render some custom template to display a proper dashboard with widgets, etc.
        // (tip: it's easier if your template extends from @EasyAdmin/page/content.html.twig)
        //
        // return $this->render('some/path/my-dashboard.html.twig');

In the future, we'll allow to show widgets, stats, etc. in the Dashboard page. Meanwhile, what I do in most of my apps is to just redirect to the most common action I do in that backend.

E.g. if the most important for you is to work with Mail entity, then do this:

class DashboardController extends AbstractDashboardController
{
    #[Route(path: '/admin', name: 'admin')]
    public function index(): Response
    {
        $adminUrlGenerator = $this->container->get(AdminUrlGenerator::class);

        return $this->redirect($adminUrlGenerator->setController(MailCrudController::class)->generateUrl());
    }
    
    // ...
}

I hope it's more clear now.

javiereguiluz avatar Jan 20 '22 11:01 javiereguiluz

Worked for me now! Thanks!

sellrock-de avatar Jan 20 '22 13:01 sellrock-de

I'm glad this was fixed. Cheers!

javiereguiluz avatar Jan 20 '22 19:01 javiereguiluz

I had the same issue. @javiereguiluz Since the widget&stats idea sounds like a long-term project ;-) Why don't you just display the main menu alongside the Welcome screen? The reason why people didn't create a custom template is that they probably didn't know what to write there ;-) And not being redirected to some (arbitrary) crud controller straight away was one of the advantages of some past upgrade. So if you just bring back the menu, I guess everybody is happy :-)

ThomasLandauer avatar Jan 27 '22 22:01 ThomasLandauer

@ThomasLandauer some people have reported this "error" ... but we still think that the real error is to never customize the Dashboard page.

That's why in #5007 we've changed the wording to be more clear about why developers don't see the menu. We also provide links to new docs explaining how to customize this. This will hopefully help most users fix this error. Thanks!

javiereguiluz avatar Jan 30 '22 12:01 javiereguiluz

@javiereguiluz

  • But this still is a BC break, isn't it? If you're upgrading from a previous version, you just get the new welcome page, and the menu is gone, right?
  • And the upcoming new "widget system" will display the menu too, right? So I still don't understand why you can't just show the menu always?

ThomasLandauer avatar Jan 30 '22 12:01 ThomasLandauer