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

[BUGFIX] Eliminate side-effects from ForViewHelper #820

Merged
merged 5 commits into from
Nov 21, 2023

Conversation

s2b
Copy link
Contributor

@s2b s2b commented Oct 16, 2023

The previous implementation overwrote template variables with the same name as the specified ViewHelper parameters "as", "key", or "iteration". With the new implementation, the variable state before the ViewHelper call gets restored once the ViewHelper call is completed.

@s2b
Copy link
Contributor Author

s2b commented Oct 16, 2023

Just noticed that this would break the following hack/work-around:

<f:for each="{items}" as="item">
  <f:variable name="lastItem" value="{item}" />
</f:for>

Maybe we need some kind of merge logic here?

@s2b s2b force-pushed the bugfix/forWithoutSideEffects branch from d635fda to beac964 Compare October 18, 2023 14:23
@s2b
Copy link
Contributor Author

s2b commented Oct 18, 2023

The new version of this patch should resolve this problem.

@s2b s2b requested review from sbuerk and lolli42 November 14, 2023 16:46
@s2b
Copy link
Contributor Author

s2b commented Nov 20, 2023

I think that there is still an edge case here:

<f:variable name="lastItem" value="fallback" />
<f:for each="{items}" as="item">
  <f:variable name="lastItem" value="{item}" />
</f:for>

In this case, lastItem would always be fallback because the variable gets restored to its initial state after the loop.

Edit: Checked it with tests, this is in fact NOT the case, because only variables defined by f:for will be reset.

@s2b s2b force-pushed the bugfix/forWithoutSideEffects branch from c7873f2 to aac1ef4 Compare November 20, 2023 12:04
The previous implementation overwrote template variables with the
same name as the specified ViewHelper parameters "as", "key",
or "iteration". With the new implementation, the variable state
before the ViewHelper call gets restored once the ViewHelper
call is completed.
@s2b s2b force-pushed the bugfix/forWithoutSideEffects branch from aac1ef4 to 36fcb71 Compare November 21, 2023 19:03
@s2b s2b merged commit a19885a into TYPO3:main Nov 21, 2023
2 checks passed
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

Successfully merging this pull request may close these issues.

2 participants