Hauke
Hauke

Reputation: 267

Symfony4 MakerBundle Own Crud Maker

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.

Upvotes: 2

Views: 1119

Answers (2)

Abdi
Abdi

Reputation: 11

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 }

Upvotes: 1

Carl Owens
Carl Owens

Reputation: 1292

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.

Upvotes: 3

Related Questions