How to use Ajax within Sonata Admin forms?

后端 未结 4 1725
有刺的猬
有刺的猬 2020-11-28 22:10

I have a Merchant entity with the following fields and associations:-

/**
 * @ORM\\ManyToMany(targetEntity=\"Category\", inversedBy=\"merchants\")
 */
public         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 22:30

    Very detailed post, just to update the way of override and use the edit template in the Admin class.
    Now, you should do it this way:

    // src/AppBundle/Admin/EntityAdmin.php  
    
    class EntityAdmin extends Admin
    {  
        public function getTemplate($name)
        {
            if ( $name == "edit" ) 
            {
                // template 'base_edit.html.twig' placed in app/Resources/views/Entity
                return 'Entity/base_edit.html.twig' ;
            }
            return parent::getTemplate($name);
        }
    }
    

    Or inject it in the service definition used the provided method, to keep the Admin class as cleaner as possible:

    // app/config/services.yml  
    
    app.admin.entity:
        class: AppBundle\Admin\EntityAdmin
        arguments: [~, AppBundle\Entity\Entity, ~]
        tags:
            - {name: sonata.admin, manager_type: orm, group: "Group", label: "Label"}
        calls:
            - [ setTemplate, [edit, Entity/base_edit.html.twig]]
    

提交回复
热议问题