Implement Product in EasyAdmin

This commit is contained in:
Tim 2021-12-29 01:03:08 +01:00
parent e990ddbc25
commit ce7bd7a3eb
6 changed files with 100 additions and 24 deletions

View File

@ -0,0 +1,39 @@
<?php
namespace App\Controller\Admin;
use App\Entity\Product;
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
{
public function __construct(private AdminUrlGenerator $adminUrlGenerator)
{
}
#[Route('/admin', name: 'admin')]
public function index(): Response
{
return $this->redirect($this->adminUrlGenerator->setController(ProductCrudController::class)->generateUrl());
}
public function configureDashboard(): Dashboard
{
return Dashboard::new()
->setTitle('IceCold');
}
public function configureMenuItems(): iterable
{
// yield MenuItem::linktoRoute('Back to home', 'fas fa-home', 'home');
yield MenuItem::section('Products', 'fas fa-folder-open');
yield MenuItem::linkToDashboard('Dashboard', 'fa fa-home');
yield MenuItem::linkToCrud('Products', 'fas fa-list', Product::class);
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace App\Controller\Admin;
use App\Entity\Product;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
class ProductCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Product::class;
}
public function configureFields(string $pageName): iterable
{
$fields = [];
switch ($pageName) {
case Crud::PAGE_INDEX:
case Crud::PAGE_DETAIL:
$fields[] = IdField::new('id');
}
$fields[] = BooleanField::new('enabled');
$fields[] = TextField::new('name');
$fields[] = TextEditorField::new('description');
return $fields;
}
}

View File

@ -11,6 +11,6 @@ class TestController extends AbstractController
#[Route('/1')]
public function test1()
{
return $this->render('base.html.twig');
return $this->render('base/base.html.twig');
}
}

View File

@ -20,7 +20,7 @@ class Product
private $name;
#[ORM\Column(type: 'text', nullable: true)]
private $Description;
private $description;
public function getId(): ?int
{
@ -41,12 +41,12 @@ class Product
public function getDescription(): ?string
{
return $this->Description;
return $this->description;
}
public function setDescription(?string $Description): self
public function setDescription(?string $description): self
{
$this->Description = $Description;
$this->description = $description;
return $this;
}

View File

@ -16,25 +16,7 @@
{% endblock %}
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
<div class="container-fluid">
<i class="bi-shop" style="font-size: 2rem; padding-right: 0.5rem; color: white;"></i>
<a class="navbar-brand" href="#">IceCold</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav me-auto mb-2 mb-md-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
</div>
</div>
</nav>
{% include 'base/navbar.html.twig' %}
<main>
{% block body %}
{% endblock %}

View File

@ -0,0 +1,19 @@
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
<div class="container-fluid">
<i class="bi-shop" style="font-size: 2rem; padding-right: 0.5rem; color: white;"></i>
<a class="navbar-brand" href="#">IceCold</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav me-auto mb-2 mb-md-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ path('admin') }}">Admin</a>
</li>
</ul>
</div>
</div>
</nav>