Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to change length constraints validation of message #650

Open
morganKa opened this issue Apr 12, 2018 · 3 comments
Open

Possibility to change length constraints validation of message #650

morganKa opened this issue Apr 12, 2018 · 3 comments

Comments

@morganKa
Copy link

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 !

@morganKa morganKa changed the title Possibility to change length constraints of message Possibility to change length constraints validation of message Apr 12, 2018
@aless673
Copy link

aless673 commented Oct 12, 2018

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

@rimoi
Copy link

rimoi commented Apr 19, 2019

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

@aless673
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants