Skip to content

Commit e746084

Browse files
committed
links ok
1 parent 8186758 commit e746084

5 files changed

+47
-2
lines changed

src/Controller/Admin/DashboardController.php

+1
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,6 @@ public function configureMenuItems(): iterable
4848
yield MenuItem::linkToDashboard('Dashboard', 'fa fa-home');
4949
// yield MenuItem::linkToCrud('The Label', 'fas fa-list', EntityClass::class);
5050
yield MenuItem::linkToCrud('Fonctions', 'fa fa-list', PhpFunction::class);
51+
yield MenuItem::linkToCrud('Liens', 'fa fa-list', LinkPhp::class);
5152
}
5253
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace App\Controller\Admin;
4+
5+
use App\Entity\LinkPhp;
6+
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
7+
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
8+
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
9+
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
10+
11+
class LinkPhpCrudController extends AbstractCrudController
12+
{
13+
public static function getEntityFqcn(): string
14+
{
15+
return LinkPhp::class;
16+
}
17+
18+
19+
public function configureFields(string $pageName): iterable
20+
{
21+
return [
22+
23+
TextField::new('title'),
24+
TextEditorField::new('description'),
25+
TextField::new('url'),
26+
];
27+
}
28+
29+
}

src/Controller/Admin/PhpFunctionCrudController.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
namespace App\Controller\Admin;
44

5+
use App\Entity\LinkPhp;
56
use App\Entity\PhpFunction;
67
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
78
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
89
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
910
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
1011
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
11-
use EasyCorp\Bundle\EasyAdminBundle\Field\CodeEditorField;
12+
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
13+
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
14+
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
1215

1316
class PhpFunctionCrudController extends AbstractCrudController
1417
{
@@ -38,6 +41,11 @@ public function configureFields(string $pageName): iterable
3841
TextField::new('slug'),
3942
TextField::new('description'),
4043
TextEditorField::new('text'),
44+
AssociationField::new('Link')->setFormTypeOptions([
45+
'by_reference' => false, // Important pour les relations Many-to-Many
46+
]),
47+
BooleanField::new('visibility')->setValue(true),
48+
DateTimeField::new('createdAt')->setValue(new \DateTime()),
4149

4250
];
4351
}

src/Entity/LinkPhp.php

+4
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,8 @@ public function removePhpFunction(PhpFunction $phpFunction): static
106106

107107
return $this;
108108
}
109+
public function __toString()
110+
{
111+
return $this->title;
112+
}
109113
}

src/Entity/PhpFunction.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,11 @@ public function getCreatedAt(): ?DateTimeInterface
144144
return $this->createdAt;
145145
}
146146

147-
public function setCreatedAt(DateTimeInterface $createdAt): static
147+
public function setCreatedAt(?DateTimeInterface $createdAt): static
148148
{
149+
if($createdAt === null){
150+
$createdAt = new \DateTime();
151+
}
149152
$this->createdAt = $createdAt;
150153

151154
return $this;

0 commit comments

Comments
 (0)