added avatar

This commit is contained in:
tracer 2022-04-12 19:00:21 +02:00
parent b562f3cae8
commit 2dfe0070e2
1 changed files with 46 additions and 20 deletions

View File

@ -5,12 +5,18 @@ namespace App\Controller\Admin;
use App\Entity\Projects; use App\Entity\Projects;
use App\Entity\Quotes; use App\Entity\Quotes;
use App\Entity\User; use App\Entity\User;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard; use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem; use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
use EasyCorp\Bundle\EasyAdminBundle\Config\UserMenu;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController; use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\User\UserInterface;
/** /**
* *
@ -18,24 +24,44 @@ use Symfony\Component\Routing\Annotation\Route;
class DashboardController extends AbstractDashboardController class DashboardController extends AbstractDashboardController
{ {
#[isGranted(data: 'ROLE_ADMIN')] #[isGranted(data: 'ROLE_ADMIN')]
#[Route(path: '/admin', name: 'admin')] #[Route(path: '/admin', name: 'admin')]
public function index(): Response public function index(): Response
{ {
//return parent::index(); //return parent::index();
return $this->render(view: 'admin/index.html.twig'); return $this->render(view: 'admin/index.html.twig');
} }
public function configureDashboard(): Dashboard public function configureDashboard(): Dashboard
{ {
return Dashboard::new() return Dashboard::new()
->setTitle(title: '24unix Admin'); ->setTitle(title: '24unix Admin');
} }
public function configureMenuItems(): iterable public function configureMenuItems(): iterable
{ {
yield MenuItem::linkToDashboard(label: 'Dashboard', icon: 'fa fa-dashboard'); yield MenuItem::linkToUrl(label: 'Homepage', icon: 'fa fa-home', url: $this->generateUrl(route: 'app_main'));
yield MenuItem::linkToCrud(label: 'Projects', icon: 'fa fa-file-code-o', entityFqcn: Projects::class); yield MenuItem::linkToDashboard(label: 'Dashboard', icon: 'fa fa-dashboard');
yield MenuItem::linkToCrud(label: 'Users', icon: 'fa fa-users', entityFqcn: User::class); yield MenuItem::linkToCrud(label: 'Projects', icon: 'fa fa-file-code-o', entityFqcn: Projects::class);
yield MenuItem::linkToCrud(label: 'Quotes', icon: 'fa fa-quote-left', entityFqcn: Quotes::class); yield MenuItem::linkToCrud(label: 'Users', icon: 'fa fa-users', entityFqcn: User::class);
} yield MenuItem::linkToCrud(label: 'Quotes', icon: 'fa fa-quote-left', entityFqcn: Quotes::class);
}
public function configureUserMenu(UserInterface $user): UserMenu
{
if (!$user instanceof User) {
throw new Exception(message: 'Wrong User!');
}
return parent::configureUserMenu(user: $user)
->setAvatarUrl(url: $user->getAvatar());
}
public function configureActions(): Actions
{
return parent::configureActions()
->add(pageName: Crud::PAGE_INDEX, actionNameOrObject: Action::DETAIL);
}
} }