简体   繁体   中英

Can't make work child admin in sonata admin bundle

I have a simple relation model in my project, I have requests and comments and created admins classes for both entities. They works just fine as separate admins, and all relations works fine on a public part of the project, but I can't set up comments as a child admin class for requests.

here is what I have in services.yaml

admin.maintenanceRequest:
        class: App\Admin\MaintenanceRequestAdmin
        arguments: [~, App\Entity\MaintenanceRequest ,~]
        tags:
            - {name: sonata.admin, manager_type: orm, label: Maintenance }
        public: true
        calls:
            - [ addChild, ['@App\Admin\MaintenanceCommentAdmin', 'maintenance_request_id']]

I also defined $parentAssociationMapping in my child admin class:

protected $parentAssociationMapping = 'maintenance_request_id';

But it leads to this error:

Cannot autowire service "App\\Admin\\MaintenanceCommentAdmin": argument "$code" of method "Sonata\\AdminBundle\\Admin\\AbstractAdmin::__construct()" has no type-hint, you should configure its value explicitly.

I tried to find solution on my own for quite a while, but seems like no one have problem with that. Hope someone can help me, Im really new to sonata and coding in general, any help would be greatly appreciated. I'll provide any additional info if it's required.

I just found a solution: change your

    - [ addChild, ['@App\Admin\MaintenanceCommentAdmin', 'maintenance_request_id']]

with

    - [ addChild, ['@admin.maintenanceComment', 'maintenance_request_id']]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM