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

Eel Helper Array.push auto cast string to array. #2710

Closed
mhsdesign opened this issue Feb 27, 2022 · 1 comment
Closed

Eel Helper Array.push auto cast string to array. #2710

mhsdesign opened this issue Feb 27, 2022 · 1 comment

Comments

@mhsdesign
Copy link
Member

Description

The eel helper Array.concat auto casts non array arguments to arrays, how about to do the same 'magic' for Array.push ?

Steps to Reproduce

use Array.push on a string like Array.push("foo", "bar")

Expected behavior

expect some auto cast magic, so we get ["foo", "bar"] as result.

Actual behavior

type php error, iterable is expected.

Usecase in Neos.Fusion:

this way one could add via @process in fusion super easily an additional css class, even if the class was a string before:

currently: https://github.com/neos/neos-development-collection/blob/a48994472e5dd0fec137f41a51bca5a710879c86/Neos.Neos/Resources/Private/Fusion/Prototypes/ContentCollection.fusion#L32

then, given any of these fusion configurations:

1.)
attributes.class = "class1 class2"
2.)
attributes.class = ${["class1", "class2"]}
3.)

attributes.class = Neos.Fusion:DataStructure {
    class1 = "class1"
    class2 = "class2"
}

the following process would be working for each config despite array or string
attributes.class.@process.addClass = ${Array.push(value, "class3")}

after @process

1.)
["class1 class2", "class3"]
2.)
["class1", "class2", "class3"]
2.)
["class1" => "class1", "class2" => "class2", 0 => "class3"]

the rendered html would be for all the same:
class="class1 class2 class3"

@albe
Copy link
Member

albe commented Feb 27, 2022

Very good and valid case in point you make there. One case where usability overrules API typing strictness. I like the idea 👍

@mhsdesign mhsdesign changed the title FEATURE: Eel Helper Array.push auto cast string to array. Eel Helper Array.push auto cast string to array. Mar 13, 2022
mhsdesign added a commit to mhsdesign/flow-development-collection that referenced this issue Mar 13, 2022
same lose behaviour exists already for `Array.concat()`
mhsdesign added a commit to mhsdesign/flow-development-collection that referenced this issue Mar 18, 2022
same lose behaviour exists already for `Array.concat()`
mhsdesign added a commit to mhsdesign/flow-development-collection that referenced this issue Mar 22, 2022
same lose behaviour exists already for `Array.concat()`
mhsdesign added a commit to mhsdesign/flow-development-collection that referenced this issue Mar 22, 2022
same lose behaviour exists already for `Array.concat()`
mhsdesign added a commit that referenced this issue Mar 22, 2022
…-2710

BUGFIX: Eel Helper `Array.push()` auto cast string to array. #2710
mhsdesign added a commit to mhsdesign/neos-development-collection that referenced this issue Mar 23, 2022
with: neos/flow-development-collection#2710

we can add any scalar types to Array.push as base, which will be auto casted to an array:
`Array.push("foo", "bar")`
which results in -> `["foo", "bar"]`
which is rendered as `foo bar`

previously we had to cast it to an array beforehand. I integrated this for the 'neos-contentcollection' once: neos#3438 - but this cleans the manual cast up.

(this also fixes any real low level css class adding via `Type.isString()` etc by just casting to an array and then pushing the new value.)

Also the last use of copy will be removed, by manually copying the (now little) code over.
fixes: neos#3588
mhsdesign added a commit to mhsdesign/neos-development-collection that referenced this issue Mar 23, 2022
with: neos/flow-development-collection#2710

we can add any scalar types to Array.push as base, which will be auto casted to an array:
`Array.push("foo", "bar")`
which results in -> `["foo", "bar"]`
which is rendered as `foo bar`

previously we had to cast it to an array beforehand. I integrated this for the 'neos-contentcollection' once: neos#3438 - but this cleans the manual cast up.

(this also fixes any real low level css class adding via `Type.isString()` etc by just casting to an array and then pushing the new value.)

Also the last use of copy will be removed, by manually copying the (now little) code over.
fixes: neos#3588
neos-bot pushed a commit to neos/neos that referenced this issue Mar 24, 2022
with: neos/flow-development-collection#2710

we can add any scalar types to Array.push as base, which will be auto casted to an array:
`Array.push("foo", "bar")`
which results in -> `["foo", "bar"]`
which is rendered as `foo bar`

previously we had to cast it to an array beforehand. I integrated this for the 'neos-contentcollection' once: neos/neos-development-collection#3438 - but this cleans the manual cast up.

(this also fixes any real low level css class adding via `Type.isString()` etc by just casting to an array and then pushing the new value.)

Also the last use of copy will be removed, by manually copying the (now little) code over.
fixes: neos/neos-development-collection#3588
neos-bot pushed a commit to neos/nodetypes-navigation that referenced this issue Mar 24, 2022
with: neos/flow-development-collection#2710

we can add any scalar types to Array.push as base, which will be auto casted to an array:
`Array.push("foo", "bar")`
which results in -> `["foo", "bar"]`
which is rendered as `foo bar`

previously we had to cast it to an array beforehand. I integrated this for the 'neos-contentcollection' once: neos/neos-development-collection#3438 - but this cleans the manual cast up.

(this also fixes any real low level css class adding via `Type.isString()` etc by just casting to an array and then pushing the new value.)

Also the last use of copy will be removed, by manually copying the (now little) code over.
fixes: neos/neos-development-collection#3588
neos-bot pushed a commit to neos/neos that referenced this issue Oct 7, 2022
with: neos/flow-development-collection#2710

we can add any scalar types to Array.push as base, which will be auto casted to an array:
`Array.push("foo", "bar")`
which results in -> `["foo", "bar"]`
which is rendered as `foo bar`

previously we had to cast it to an array beforehand. I integrated this for the 'neos-contentcollection' once: neos/neos-development-collection#3438 - but this cleans the manual cast up.

(this also fixes any real low level css class adding via `Type.isString()` etc by just casting to an array and then pushing the new value.)

Also the last use of copy will be removed, by manually copying the (now little) code over.
fixes: neos/neos-development-collection#3588
neos-bot pushed a commit to neos/nodetypes-navigation that referenced this issue Oct 7, 2022
with: neos/flow-development-collection#2710

we can add any scalar types to Array.push as base, which will be auto casted to an array:
`Array.push("foo", "bar")`
which results in -> `["foo", "bar"]`
which is rendered as `foo bar`

previously we had to cast it to an array beforehand. I integrated this for the 'neos-contentcollection' once: neos/neos-development-collection#3438 - but this cleans the manual cast up.

(this also fixes any real low level css class adding via `Type.isString()` etc by just casting to an array and then pushing the new value.)

Also the last use of copy will be removed, by manually copying the (now little) code over.
fixes: neos/neos-development-collection#3588
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants