EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

Make the "ea" global variable dynamic

Open nicolas-grekas opened this issue 10 months ago • 7 comments

My tentative fix for #5986

nicolas-grekas avatar Apr 19 '24 15:04 nicolas-grekas

This could definitely be a solution that could work for us 🙏 Nicolas, thanks a lot for working on this. I'm going to test and look into this very soon!

You've probably seen it but ... in https://github.com/twigphp/Twig/issues/4007 some people are reporting that they face a similar issue but when using Shopware instead of EasyAdmin. I don't know if there's a way to solve this at Twig level for all projects, but I just wanted to mention it. Thanks!

javiereguiluz avatar Apr 19 '24 15:04 javiereguiluz

I tried relying on __call but that breaks the CI so I reverted to listing methods explicitly.

About shopware/etc. I suppose they do the same mistake. Possibly a RefreshGlobalsInterface could help. Or Twig could always refresh globals coming from extensions on reset. Anyway, that's not a short term solution for EA so not applicable.

A better option would be to deprecate the global and replace it with a function. This PR gives a hook to do so. This would have the benefit of freeing the hot path from loading anything related to EA, and I suppose that'd be the same for shopware.

My TL;DR is: don't use globals for non-static values.

nicolas-grekas avatar Apr 19 '24 15:04 nicolas-grekas

this will still break if templates do things like {% if ea is defined %}

stof avatar Apr 19 '24 15:04 stof

this will still break if templates do things like {% if ea is defined %}

True, and there is no way around this so we have to go with it IMHO.

nicolas-grekas avatar Apr 19 '24 15:04 nicolas-grekas

Is this PR also fixing this issue with another approach?

Seb33300 avatar May 05 '24 05:05 Seb33300

Both should be merged, and a deprecation should be added here. Note that the getGlobals() method should be deprecated soon in twig.

nicolas-grekas avatar May 05 '24 06:05 nicolas-grekas

Thanks for the fix @nicolas-grekas! Is this PR going to be merged soon?

AykutCevik avatar Jul 16 '24 19:07 AykutCevik

Yes thanks a lot, same question, is this will be merged soon?

laferte-tech avatar Aug 29 '24 11:08 laferte-tech

@nicolas-grekas how can we work around the problem while waiting for the PR to be merged, because currently my back office is completely blocked due to the error.

Skewmos avatar Sep 01 '24 09:09 Skewmos

LGTM

fabpot avatar Sep 07 '24 13:09 fabpot

Hi @nicolas-grekas Can I set up decorated services while waiting for them to be merged?

dunglt90vt avatar Oct 01 '24 09:10 dunglt90vt

Very late, but this is finally merged. Thanks Nicolas!

javiereguiluz avatar Oct 12 '24 13:10 javiereguiluz