Skip to content

Possibility to change length constraints validation of message #650

Open

Description

@morganKa

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 !

Activity

  1. changed the title [-]Possibility to change length constraints of message[/-] [+]Possibility to change length constraints validation of message[/+] on Apr 12, 2018
  2. aless673 commented on Oct 12, 2018

    @aless673

    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

  3. sle160292 commented on Apr 19, 2019

    @sle160292

    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

  4. aless673 commented on Apr 21, 2019

    @aless673

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions