Configure EasyAdmin

This commit is contained in:
2024-07-27 22:24:27 -04:00
parent db3842abb6
commit afa8242399
4 changed files with 113 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Controller\Admin;
use App\Entity\Comment;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
class CommentCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Comment::class;
}
/*
public function configureFields(string $pageName): iterable
{
return [
IdField::new('id'),
TextField::new('title'),
TextEditorField::new('description'),
];
}
*/
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Controller\Admin;
use App\Entity\Conference;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
class ConferenceCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Conference::class;
}
/*
public function configureFields(string $pageName): iterable
{
return [
IdField::new('id'),
TextField::new('title'),
TextEditorField::new('description'),
];
}
*/
}

View File

@@ -0,0 +1,53 @@
<?php
namespace App\Controller\Admin;
use App\Entity\Comment;
use App\Entity\Conference;
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class DashboardController extends AbstractDashboardController
{
#[Route('/admin', name: 'admin')]
public function index(): Response
{
$routeBuilder = $this->container->get(AdminUrlGenerator::class);
$url = $routeBuilder->setController(ConferenceCrudController::class)->generateUrl();
return $this->redirect($url);
// 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');
}
public function configureDashboard(): Dashboard
{
return Dashboard::new()
->setTitle('Guestbook');
}
public function configureMenuItems(): iterable
{
yield MenuItem::linkToRoute('Back to the website', 'fas fa-home', 'homepage');
yield MenuItem::linkToCrud('Conferences', 'fas fa-map-marker-alt', Conference::class);
yield MenuItem::linkToCrud('Comments', 'fas fa-comments', Comment::class);
}
}

View File

@@ -35,6 +35,10 @@ class Conference
$this->comments = new ArrayCollection(); $this->comments = new ArrayCollection();
} }
public function __toString(): string {
return $this->city . ' ' . $this->year;
}
public function getId(): ?int public function getId(): ?int
{ {
return $this->id; return $this->id;