Open morganKa opened 6 years ago
Hi,
I was facing the same problem and i resolved it by using Form Extension : https://symfony.com/doc/3.4/form/create_form_type_extension.html
src/AppBundle/Form/Extension/CommentTypeExtension.php
namespace AppBundle\Form\Extension;
use FOS\CommentBundle\Form\CommentType;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\OptionsResolver\OptionsResolver;
class CommentTypeExtension extends AbstractTypeExtension
{
/**
* Returns the name of the type being extended.
*
* @return string The name of the type being extended
*/
public function getExtendedType()
{
return CommentType::class;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefault('validation_groups', array('AppComment'));
}
}
app/config/services.yml
AppBundle\Form\Extension\CommentTypeExtension:
tags:
- { name: form.type_extension, extended_type: FOS\CommentBundle\Form\CommentType }
src/AppBundle/Resources/config/validation.yml
FOS\CommentBundle\Model\Comment:
properties:
body:
- Length:
min: 3
minMessage: Whatever you want
groups: [ "AppComment"]
Can also solve #252 and #444
hello aless673, I tried to do like you, but i have an error :
(2/2) LoaderLoadException
There is no extension able to load the configuration for
"FOS\CommentBundle\Model\Comment" (in /var/www/web/config/packages/validator.yaml).
Looked for namespace "FOS\CommentBundle\Model\Comment",
found "fos_js_routing", "doctrine_cache", "doctrine", "doctrine_migrations",
"sensio_framework_extra", "monolog", "security", "swiftmailer",
"twig", "web_server", "maker", "debug", "web_profiler", "acl",
"framework", "liip_imagine", "knp_gaufrette", "vich_uploader",
"exercise_html_purifier", "presta_sitemap", "jms_serializer",
"fos_rest", "fos_comment", "fos_user", "nelmio_api_doc",
"snc_redis", "stfalcon_tinymce", "eight_points_guzzle",
"fos_elastica", "stof_doctrine_extensions", "hwi_oauth",
"httplug", "crawler_detect", "webpack_encore", "mercure"
in /var/www/web/config/packages/validator.yaml
(which is loaded in resource "/var/www/web/config/packages/validator.yaml").
Note: I Use Symfony 4.2
Thanks
hello aless673, I tried to do like you, but i have an error :
(2/2) LoaderLoadException There is no extension able to load the configuration for "FOS\CommentBundle\Model\Comment" (in /var/www/web/config/packages/validator.yaml). Looked for namespace "FOS\CommentBundle\Model\Comment", found "fos_js_routing", "doctrine_cache", "doctrine", "doctrine_migrations", "sensio_framework_extra", "monolog", "security", "swiftmailer", "twig", "web_server", "maker", "debug", "web_profiler", "acl", "framework", "liip_imagine", "knp_gaufrette", "vich_uploader", "exercise_html_purifier", "presta_sitemap", "jms_serializer", "fos_rest", "fos_comment", "fos_user", "nelmio_api_doc", "snc_redis", "stfalcon_tinymce", "eight_points_guzzle", "fos_elastica", "stof_doctrine_extensions", "hwi_oauth", "httplug", "crawler_detect", "webpack_encore", "mercure" in /var/www/web/config/packages/validator.yaml (which is loaded in resource "/var/www/web/config/packages/validator.yaml").
Note: I Use Symfony 4.2
Thanks
Hi, it seems that your validator.yaml is in the wrong directory for Symfony 4.2
Try to put it in :
config/validator/validation.yaml
Hey !
Have you planned the possibiliy to override the min length of the body by adding a group or something ? My users are annoyed 'cause they can't comment with :) !
Thanks !