Unable to override standard skeleton views in Symfony2 GeneratorBundle

I am unable to override the skeleton representations of the generator.

At first I tried to add my view to /app/Resources/SensioGeneratorBundle/skeleton/crud/views/index.html.twig

This did not work, so I tried to create a new Bundle extending the SensioGeneratorBundle and copying my view into the Resources folder.

I already manage to use themes for twig forms, but I need to personalize the views generated by the doctrine: generate: crud command.

+6
source share
2 answers

First of all: the corresponding types of skeleton are located here:

vendor/bundles/Sensio/Bundle/GeneratorBundle/Resources/skeleton/crud 

Quick and dirty, you should be fine overriding these view files - but that's not what we want;)

IN:

 vendor/bundles/Sensio/Bundle/GeneratorBundle/Command/GenerateDoctrineCrudCommand.php 

there is an accessor for the generator:

 protected function getGenerator() { if (null === $this->generator) { $this->generator = new DoctrineCrudGenerator($this->getContainer()->get('filesystem'), __DIR__.'/../Resources/skeleton/crud'); } return $this->generator; } 

You can try to override this method in the Bundle extension and set another $skeletonDir in the constructor.

Edit:

A quick example in my test environment how this can be achieved (I just did a quick test;):

Create a new package for the custom generator: php app/console generate:bundle and follow the instructions. The route is not needed. I chose for this example: Acme / CrudGeneratorBundle (or use an existing package)

Create a folder named "Command" in the new package directory.

Put the command class in this folder.

 <?php //src/Acme/CrudGeneratorBundle/Command/MyDoctrineCrudCommand.php namespace Acme\CrudGeneratorBundle\Command; use Sensio\Bundle\GeneratorBundle\Generator\DoctrineCrudGenerator; class MyDoctrineCrudCommand extends \Sensio\Bundle\GeneratorBundle\Command\GenerateDoctrineCrudCommand { protected function configure() { parent::configure(); $this->setName('mydoctrine:generate:crud'); } protected function getGenerator() { $generator = new DoctrineCrudGenerator($this->getContainer()->get('filesystem'), __DIR__.'/../Resources/skeleton/crud'); $this->setGenerator($generator); return parent::getGenerator(); } } 

Copy the provider / packages / Sensio / Bundle / GeneratorBundle / Resources / skeleton / crud to your resources (in my example "src / Acme / CrudGeneratorBundle / Resources / crud")

+8
source

It was the best solution for me: symfony2-how-to-override-core-template

does not add a command, but changes the skeleton for this particular package.

+1
source

All Articles