Giter VIP home page Giter VIP logo

Comments (11)

kozmenkoav avatar kozmenkoav commented on August 17, 2024 1

The same problem. I made category entity translatable, so I don't need name field of original entity to be required. How I can remove/override constraint defined in validation.xml?

from sonataclassificationbundle.

Tim4c avatar Tim4c commented on August 17, 2024 1

Ok after few hours, i finally found a way to solve the problem...
I think, it's not the best way (any idea...), because if you need to update the max length value, you have to update two files.

In your CategoryAdmin class

    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
          ->add('name', null, array(
            'attr' => array(
              'maxlength' => 200
            )
          ))
        ;
    }

    public function getFormBuilder() {
        //OverrideCategoryValidation => custom validation group
        $this->formOptions = array('validation_groups' => 'OverrideCategoryValidation');

        $formBuilder = parent::getFormBuilder();
        return $formBuilder;
    }

and in your category entity class :

use Symfony\Component\Validator\Constraints as Assert;
    /**
     * @Assert\Length(
     *      min = 2,
     *      max = 200,
     *      groups={"OverrideCategoryValidation"}, 
     *      minMessage = "Your first name must be at least {{ limit }} characters long",
     *      maxMessage = "Your first name cannot be longer than {{ limit }} characters"
     * )
     */
    protected $name;

from sonataclassificationbundle.

alebo avatar alebo commented on August 17, 2024 1

It's possible to exclude vendor's validation in a compiler pass. Then you can just copy validation.xml to your inherited bundle and maintain it there.

Here's a quick implementation (not tested):

        $validatorBuilder = $container->getDefinition('validator.builder');

        foreach ($validatorBuilder->getMethodCalls('addXmlMappings') as $call) {
            if ('addXmlMappings' == $call[0]) {
                $validatorBuilder->removeMethodCall($call[0]);
                $arguments = array();
                foreach ($call[1][0] as $path) {
                    if (false !== strpos($path, 'sonata-project/classification-bundle/Resources/config/validation.xml')) {
                        continue;
                    }
                    $arguments[]= $path;
                }
                $validatorBuilder->addMethodCall($call[0], array($arguments));

                break;
            }
        }

from sonataclassificationbundle.

soullivaneuh avatar soullivaneuh commented on August 17, 2024

Please try to clear all the cache and try again.

from sonataclassificationbundle.

pirasterize avatar pirasterize commented on August 17, 2024

Thanks for answer
I already tried many times clearing cache (rm -rf app/cache/*), right now again...

from sonataclassificationbundle.

tolstoyleo avatar tolstoyleo commented on August 17, 2024

I'm having this exact same issue. it doesn't work with moving the validation.xml file to your own bundle's config, nor does it work by overriding the validate method as stated in the document, my overridden method in my own admin class looks like this:

$errorElement
        ->with('name')
            ->assertLength(array('max' => 50))
        ->end()
    ;

so now if i submit a text > 32, i get the error that says the value is too long, it should be 32 characters or less. and when it's over 50... i get BOTH ERRORS about 32 chars and 50.

What am i not doing right here?

from sonataclassificationbundle.

OskarStark avatar OskarStark commented on August 17, 2024

Ping @rande

from sonataclassificationbundle.

Tim4c avatar Tim4c commented on August 17, 2024

Have you found any solution ?

from sonataclassificationbundle.

kozmenkoav avatar kozmenkoav commented on August 17, 2024

No, unfortunately.

from sonataclassificationbundle.

StanislavUngr avatar StanislavUngr commented on August 17, 2024

Hello guys. Have anybody found a way to remove property validation from already defined class? Im solving the same issue as @kozmenkoav - moving Category->name into Translatable...

from sonataclassificationbundle.

stale avatar stale commented on August 17, 2024

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

from sonataclassificationbundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.