symfony2admingenerator / AdmingeneratorGeneratorBundle

(old-legacy) Admingenerator for Symfony2, parse generator.yml files to build classes
http://symfony2admingenerator.org/
MIT License
360 stars 125 forks source link

Extend ExcelController from the user project ListController #813

Open Restless-ET opened 9 years ago

Restless-ET commented 9 years ago

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:

Any ideas @loostro , @bobvandevijver ?

Regards

ioleo commented 9 years ago

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.

Restless-ET commented 9 years ago

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.

ioleo commented 9 years ago

@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

bobvandevijver commented 9 years ago

@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?

Restless-ET commented 9 years ago

@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. :-/

Restless-ET commented 9 years ago

@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.

bobvandevijver commented 9 years ago

@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).

Restless-ET commented 9 years ago

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

Also, :+1: for the code change on the bundle.