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

Make the "ea" global variable dynamic #6273

Merged
merged 1 commit into from
Oct 12, 2024

Conversation

nicolas-grekas
Copy link
Contributor

My tentative fix for #5986

@javiereguiluz
Copy link
Collaborator

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 twigphp/Twig#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 javiereguiluz added the priority: important Bugs to fix and features to implement label Apr 19, 2024
Copy link

@dunglas dunglas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

src/Provider/AdminContextProvider.php Outdated Show resolved Hide resolved
@nicolas-grekas
Copy link
Contributor Author

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.

@stof
Copy link
Contributor

stof commented Apr 19, 2024

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

@nicolas-grekas
Copy link
Contributor Author

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.

@Seb33300
Copy link
Contributor

Seb33300 commented May 5, 2024

Is this PR also fixing this issue with another approach?

@nicolas-grekas
Copy link
Contributor Author

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

@AykutCevik
Copy link

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

@laferte-tech
Copy link

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

@Skewmos
Copy link

Skewmos commented Sep 1, 2024

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

@fabpot
Copy link
Contributor

fabpot commented Sep 7, 2024

LGTM

@dunglt90vt
Copy link

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

@javiereguiluz javiereguiluz added this to the 4.x milestone Oct 12, 2024
@javiereguiluz javiereguiluz merged commit c90cfb1 into EasyCorp:4.x Oct 12, 2024
11 checks passed
@javiereguiluz
Copy link
Collaborator

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

javiereguiluz added a commit that referenced this pull request Oct 14, 2024
This PR was merged into the 4.x branch.

Discussion
----------

`ea` twig variable existence check fix

Fix for #6473

Added `hasContext` method to check for AdminContext existence instead of relying on `is defined`.
#6273 made `ea` twig global variable always defined.

Commits
-------

6c817f9 Add hasContext in AdminContextProvider
@nicolas-grekas nicolas-grekas deleted the ea-admin-context branch January 22, 2025 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: important Bugs to fix and features to implement
Projects
None yet
Development

Successfully merging this pull request may close these issues.