symfony2admingenerator / AdmingeneratorGeneratorBundle

(old-legacy) Admingenerator for Symfony2, parse generator.yml files to build classes

Home Page:http://symfony2admingenerator.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Extend ExcelController from the user project ListController

Restless-ET opened this issue · comments

Hi there,

Is there a way for the generated ExcelController to extend from the user project ListController class instead of using the base ListController created on the cache folder?

As this is right now.. if we override, for instance, the processQuery($query) or processFilters($query) method on our ListController class those changes won't be taken in consideration by the ExcelController thus forcing us to either:

  • Redeclare the entire ExcelController by copying all the functions from the generated one on our custom project and make it extend our ListController (thus making the excel builder in our *-generator.yml file obsolete );
  • Copy all methods that were extended on our ListController into our ExcelController class ( thus having to maintain the same code in two different places :\ ).

Any ideas @loostro , @bobvandevijver ?

Regards

Maybe you put in app/Resources/AdmingeneratorGeneratorBundle/templates/CommonAdmin/ExcelAction/ExcelBuilderAction.php.twig

a copy of the original ExcelBuilderAction.php.twig

and add replace line 15 with:

use {{ namespace }}\Controller{{ prefix ? "\\" ~ prefix : "" }}\ListController as CustomListController;

class ExcelController extends CustomListController

at the top.

This should trigger the symfony2 bundle inheritance and use your custom template to generate ExcelBuilder controller and the custom use should point to the correct (customized) controller.

Hi @loostro

First of all, thanks for your reply.

I've tried your suggestion but unfortunately it does not seem to work. :(
The custom template is not used.

Any ideas?

I can always make the change in the ExcelBuilderAction.php.twig on my fork but I was trying to avoid that.

@Restless-ET thats weird.. i think you should go to symfony2 docs and study the bundle inheritance and check why this does not work.. i'm sure there is a way to use bundle inheritance to overwrite these templates

@loostro @Restless-ET I think we might be able to solve with a simple change in the ExcelBuilderAction.php.twig template. If we change line 15 from

class ExcelController extends ListController

into:

class ExcelController extends \{{ namespace_prefix }}\{{ bundle_name }}\Controller\{{ builder.generator.BaseGeneratorName }}\ListController

I think we have exactly what Restless-ET needs, without breaking anything inside the bundle for others. I've tried it in my development environment and nothings breaks, but I do not have the usage as described in this ticket. @Restless-ET: Can you test this solution?

If this works, I can create a PR for all branches. @loostro, what's your opinion?

@loostro I find that awkward as well since I've already used that method to override views from AvocodeFormExtensionsBundle. Still I'm not being able to make it work for the templates folder from this bundle. :-/

@bobvandevijver That does indeed work, I've already tried that before. I was just trying to find another solution because I didn't know if that would be a wanted/desired change on the bundle main repository code.

But if that change is ok by @loostro I don't mind create the PRs as well.

@Restless-ET Please take a look at this doc, you're probably missing the templates_dirs in your config.yml.

However, I still think that the code change is nice to do, as this is the only template which extends an action from the bundle itself (in this way at least).

Ohh.. I see.. now it works. :-) Thanks @bobvandevijver

Also, 👍 for the code change on the bundle.