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: