this code is already present in Admin class https://github.com/sonata-project/SonataAdminBundle/blob/master/Admin/Admin.php#L591