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

[FEATURE] Allow setting keys of objects #671

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

spthiel
Copy link

@spthiel spthiel commented Dec 9, 2022

Add an additional option to set the name to a period seperated path for modifying of inner values of arrays/objects for the ability to expand objects during fluid template validation

An example usecase for this would be when rendering a partial for a range input and allowing the passing of min and max as seperate parameters to additionalParameters to the f:render to then merge them inside the partial like this

Template.html

<f:render partial="RangeInput" min="0" max="100" additionalAttributes="{data-target: "rangeinput"}"

RangeInput.html

<f:variable name="additionalAttributes.min" value="{min}" />
<f:variable name="additionalAttributes.max" value="{max}" />
<f:form.textfield type="range" additionalAttributes="{additionalAttributes}"/>

This change allows for the parent to be null so in above example the additionalAttributes key is optional and if not passed the resulting additionalAttributes array would just look like ["min" => 0, "max" => 100]

Add an additional option to set the name to a period seperated path for modifying of inner values of arrays/objects for the ability to expand objects during fluid template validation
@spthiel
Copy link
Author

spthiel commented Dec 12, 2022

Saw today it's included in #425

@spthiel
Copy link
Author

spthiel commented May 5, 2023

Reopen as #425 was closed for the scope being too large

@spthiel spthiel reopened this May 5, 2023
@s2b
Copy link
Contributor

s2b commented May 11, 2023

Did you try what happens if additionalAttributes is a PHP object? I suspect that you solution wouldn't work in quite a few cases, it probably throws PHP warnings there.

In my opinion, this should only be added if we can cover (almost) all cases we cover with variable access. This would mean for example to look for object setters. And I'm not sure if it's a good idea to allow Fluid to write data into domain objects.

@spthiel
Copy link
Author

spthiel commented May 11, 2023

I definitely want to avoid anything that mutates data outside fluid (i.e. php objects) the goal of this is exclusively to allow for setting of further keys on fluid template variables

@NamelessCoder
Copy link
Contributor

See #396 (would allow array union with + operator in variable accessor syntax).

IMHO, it should not be allowed to modify properties of already-assigned variables. It's fine to replace the objects (read: arrays only, not actual objects) and it's fine to assign new objects, but modifying the existing ones is not desired. Hence, the array union operator is pretty much ideal as it creates a new combined result from two array inputs with overrules in case of key match.

@spthiel
Copy link
Author

spthiel commented Aug 16, 2023

I can accept array union as a solution to this issue

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.

3 participants