Implement Product in EasyAdmin
This commit is contained in:
		
							
								
								
									
										39
									
								
								src/Controller/Admin/DashboardController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								src/Controller/Admin/DashboardController.php
									
									
									
									
									
										Normal 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); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										36
									
								
								src/Controller/Admin/ProductCrudController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								src/Controller/Admin/ProductCrudController.php
									
									
									
									
									
										Normal 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; | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user