Symfony4 MakerBundle Own Crud Maker

若如初见. 提交于 2020-06-17 02:46:51

问题


I want to customize the boilerplate code of the new makerbundle crud maker. There is no simple overwriting the templates as it was in SensioGeneratorBundle. I tried to generate a custom MyMakeCrud based on the original code - but i struggle about the injected DoctrineEntityHelper $entityHelper.

 Cannot autowire service "App\Maker\MakeMyCrud": argument "$entityHelper" of
 method "__construct()" references class "Symfony\Bundle\MakerBundle\Doctri
 ne\DoctrineEntityHelper" but no such service exists. You should maybe alias
 this class to the existing "maker.doctrine_entity_helper" service.

The existing maker.doctrine_entity_helper is defined private in the maker bundle. How can i get the injection to run?

Could you help me? Has anyone an example for customizing the crud generation? New in sf4.


回答1:


You have to define a service for it like below:

    app.maker.make_crud:
    class: App\Maker\MakeCrud
    arguments: ['@maker.doctrine_helper']
    calls:
        - [configureCommand, ['@security.command.user_password_encoder', '@?']]
        - [interact, ['@?', '@?', '@security.command.user_password_encoder']]
    tags:
        - { name: maker.command }

I placed this in config/services.yaml.

App\Maker\MakeCrud is your crud maker class.

Should really place this in a services_dev.yaml file.

Hope this helps.




回答2:


Many thanks to both of you for this post. I had to customize the MakeCrud command too. This is the configuration which worked for me for version 5.

app.maker.make_crud:
    class: App\Maker\MakeCrudCommand
    arguments: ['@maker.doctrine_helper', '@maker.renderer.form_type_renderer']
    calls:
        - [configureCommand, ['@security.command.user_password_encoder', '@?']]
        - [interact, ['@?', '@?', '@security.command.user_password_encoder']]
    tags:
        - { name: maker.command }


来源:https://stackoverflow.com/questions/50273223/symfony4-makerbundle-own-crud-maker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!