Web development

Sonata Admin: modify validation groups in an admin extension

SonataAdminBundle has a powerful extensions feature which allows you to add or change features of one or more Admin instances.

I needed my extension to change some validation rules, and it turned out that imposing different validation groups was a good way to achieve it. 

$formOptions attribute of Sonata\AdminBundle\Admin\AbstractAdmin class allows for setting validation groups, but I couldn’t find an easy way to modify it in my extension.

getFormBuilder method of AbstractAdmin class is where these $formOptions are added to the form builder:

So, in my admin class I override this method, to add support for extensions:

Now, in your admin extension you can add a method to actually modify $formOptions of the admin class:

Recent Posts

Grandfather’s advices

I used to spend a lot of time with my grandparents in my childhood. My…

5 years ago

World. World never stops changing.

If anything is certain in this world, it is that things always change. And there…

5 years ago

How to be successful

This is the most important advice on how to be successful! Read it carefully!

8 years ago

I wanted to change WordPress URL, you won’t believe what happened afterwards

WordPress has a nasty habit of storing absolute URLs in the database. That means that…

8 years ago

Let’s Encrypt – providing free automated SSL certificates

In August 2014 Google announced that their search engine will value HTTPS as a ranking…

9 years ago

Add colors to your bash shell

Unix shell is one of the most powerful tools ever created, but sometimes it can…

9 years ago