edumedia / comment-bundle
Installs: 4 625
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=8.2
- doctrine/orm: ^3.2
- symfony/config: ^7.0
- symfony/dependency-injection: ^7.0
- symfony/framework-bundle: ^7.0
- symfony/http-kernel: ^7.0
- symfony/security-bundle: ^7.0
- symfony/twig-bridge: ^7.0
Requires (Dev)
- symfony/console: ^7.0
README
How to
Install bundle
composer require edumedia/comment-bundle
Create Comment class
<?php // src/Entity/Comment.php <?php namespace App\Entity; use Doctrine\ORM\Mapping as ORM; use eduMedia\CommentBundle\Entity\CommentInterface; use eduMedia\CommentBundle\Entity\CommentTrait; use Symfony\Component\Security\Core\User\UserInterface; #[ORM\Entity] #[ORM\Table] class Comment implements CommentInterface { use CommentTrait; #[ORM\ManyToOne(targetEntity: User::class)] private ?UserInterface $author = null; }
Make entity commentable
Here is a User example:
<?php // src/Entity/User namespace App\Entity; use eduMedia\CommentBundle\Entity\CommentableInterface; use eduMedia\CommentBundle\Entity\CommentableTrait; class User implements /* (...) */ CommentableInterface { use CommentableTrait; // (...) }
Add admin routes to list/add comments in EasyAdmin
# config/routes/edumedia_comment.yaml edumedia_comment: resource: '@eduMediaCommentBundle/Resources/config/routes.yaml' prefix: '/admin/comments'
User CRUD example
<?php // src/Controller/Admin/UserCrudController.php namespace App\Controller\Admin; use App\Entity\User; // (...) class UserCrudController extends AbstractCrudController { public function configureCrud(Crud $crud): Crud { return $crud->overrideTemplate('crud/edit', 'admin/user/edit.html.twig'); } }
{# templates/admin/user/edit.html.twig #} {% extends '@EasyAdmin/crud/edit.html.twig' %} {% block main %} {{ parent() }} {% include '@eduMediaComment/admin/comments/crud.html.twig' %} {% endblock %}
Optional: Use a non-default Comment class FCQN
# config/services.yaml services: eduMedia\CommentBundle\Service\CommentService: arguments: $commentClass: 'MyCustomApp\Entity\Comment'
Migrate, to create tables
bin/console make:migration bin/console doctrine:migrations:migrate