简体   繁体   中英

Symfony - Sonata admin - override validation

i'm using sonata admin, i tried to override max length allowed for name of categorie

I have an entity MyEntity who extend Application\Sonata\ClassificationBundle\Entity\Category

// MyEntity admin class

I put this following function, regarding https://sonata-project.org/bundles/core/master/doc/reference/conditional_validation.html#inline-validation

public function validate(\Sonata\Form\Validator\ErrorElement $errorElement, $object)
{
    parent::validate($errorElement, $object);

    $errorElement->with('name')
            ->assertLength(['max' => 100])
    ;
}

Current display

Expected to get ride of this 32 max length on name's field

Thx for helping

It looks like what you need to do instead, is override this validation config: https://github.com/sonata-project/SonataClassificationBundle/blob/3.x/src/Resources/config/validation.xml

<class name="Sonata\ClassificationBundle\Model\Category">
    <property name="name">
        <constraint name="NotBlank"/>
        <constraint name="Length">
            <option name="min">2</option>
            <option name="max">32</option>
        </constraint>
    </property>
</class>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM