How to add the input username in fosCommentBundle without fosUser?

68 Views Asked by At

I want to add the Username field (input) in bundle FOSCommentBundle without using FOSUserBundlde.

the user must enter his username and comment. The basic model does not offer the pseudo field because it relies on the connected user or "anonymous" if no connected user.

Can you tell me how to do this?

Symfony 4.4

Thank's

1

There are 1 best solutions below

0
jona303 On BEST ANSWER

The comment in the bundle is just an entity decalred in the configuration. I suppose you did that ?

Create your own comment entity

https://github.com/FriendsOfSymfony/FOSCommentBundle/blob/master/Resources/doc/2a-mapping_orm.md

So I think you just have to add new property $userName to your comment entity. I found this https://github.com/FriendsOfSymfony/FOSCommentBundle/issues/334

Overriding bundle parts

I never used that bundle but what is answered in the issue comment is pure symfony behavior. You have to override Bundle's Form and template.

That Form : https://github.com/FriendsOfSymfony/FOSCommentBundle/blob/master/Form/CommentType.php

And that template : https://github.com/FriendsOfSymfony/FOSCommentBundle/blob/master/Resources/views/Thread/comment_new_content.html.twig

To override the FormType from any bundle

https://symfony.com/doc/4.4/form/create_form_type_extension.html

and to override templates

https://symfony.com/doc/current/bundles/override.html#templates