From 37a4a3dc14f8e446aaa9774ed7f75428eefe24aa Mon Sep 17 00:00:00 2001
From: Baumes
Date: Tue, 4 Nov 2025 21:29:18 +0100
Subject: [PATCH] Fix cannot create a comment
---
.../Admin/CommentCrudController.php | 22 +++++++++++--------
src/Entity/Post.php | 5 +++++
2 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/src/Controller/Admin/CommentCrudController.php b/src/Controller/Admin/CommentCrudController.php
index 57db8fa..33da48c 100644
--- a/src/Controller/Admin/CommentCrudController.php
+++ b/src/Controller/Admin/CommentCrudController.php
@@ -5,8 +5,9 @@
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;
+use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
+use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
+use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
class CommentCrudController extends AbstractCrudController
{
@@ -15,14 +16,17 @@ public static function getEntityFqcn(): string
return Comment::class;
}
- /*
public function configureFields(string $pageName): iterable
{
- return [
- IdField::new('id'),
- TextField::new('title'),
- TextEditorField::new('description'),
- ];
+ yield IdField::new('id')->onlyOnIndex();
+ yield DateTimeField::new('publishedAt')->onlyOnIndex();
+ yield TextareaField::new('content')->onlyOnForms();
+ yield AssociationField::new('author')
+ ->setSortProperty('fullName')
+ ->onlyOnForms();
+ yield AssociationField::new('post')
+ ->setSortProperty('title')
+ ->onlyOnForms();
+ yield DateTimeField::new('publishedAt')->onlyOnForms();
}
- */
}
diff --git a/src/Entity/Post.php b/src/Entity/Post.php
index f090515..4834acc 100644
--- a/src/Entity/Post.php
+++ b/src/Entity/Post.php
@@ -53,6 +53,11 @@ public function __construct()
$this->tags = new ArrayCollection();
}
+ public function __toString(): string
+ {
+ return $this->getTitle();
+ }
+
public function getId(): ?int
{
return $this->id;