Search code examples
sonata-admin

Sonata admin configureFormFields add action


How i can add custom action to configureFormFields Admin

class ContractAdmin extends AbstractAdmin
{

    protected function configureFormFields(FormMapper $formMapper)
    {
    ///here
   }
}

I try add action to this menu

enter image description here


Solution

  • Custom admin action you add add according to the manual. What are you writing about is form fields for add / edit action.

    For the buttons, you need to override method getActionButtons

    public function getActionButtons($action, $object = null)
    {
        $actions = parent::getActionButtons($action, $object);
        if ($action == 'edit') {
            $actions['myKey'] = ['template' => 'template_path_to_render.html.twig'];
        }
        return $actions;
    }