Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend ExcelController from the user project ListController #813

Open
Restless-ET opened this issue Dec 2, 2014 · 8 comments
Open

Extend ExcelController from the user project ListController #813

Restless-ET opened this issue Dec 2, 2014 · 8 comments

Comments

@Restless-ET
Copy link
Contributor

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

@ioleo
Copy link
Member

ioleo commented Dec 7, 2014

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
Copy link
Contributor Author

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
Copy link
Member

ioleo commented Jan 28, 2015

@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
Copy link
Member

@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
Copy link
Contributor Author

@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
Copy link
Contributor Author

@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
Copy link
Member

@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
Copy link
Contributor Author

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

Also, 👍 for the code change on the bundle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants