Skip to content

Commit

Permalink
TASK: Fusion clean up the usages how @process adds css classes.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mhsdesign committed Mar 23, 2022
1 parent 01108f6 commit 2c5620c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 29 deletions.
15 changes: 3 additions & 12 deletions Resources/Private/Fusion/Prototypes/Content.fusion
Expand Up @@ -18,18 +18,9 @@ prototype(Neos.Neos:Content) < prototype(Neos.Fusion:Template) {
# attributes.class.@process.nodeType >
# }
# in your site's Fusion if you don't need that behavior.
attributes.class.@process.nodeType = Neos.Fusion:Case {
@context.nodeTypeClassName = ${String.toLowerCase(String.pregReplace(node.nodeType.name, '/[[:^alnum:]]/', '-'))}

classIsString {
condition = ${Type.isString(value)}
renderer = ${String.trim(String.trim(value) + ' ' + nodeTypeClassName)}
}

classIsArray {
condition = ${Type.isArray(value)}
renderer = ${Array.push(value, nodeTypeClassName)}
}
attributes.class.@process.nodeType = Neos.Fusion:Value {
nodeTypeClassName = ${String.toLowerCase(String.pregReplace(node.nodeType.name, '/[[:^alnum:]]/', '-'))}
value = ${Array.push(value, this.nodeTypeClassName)}
}

# The following line must not be removed as it adds required meta data to all content elements in backend
Expand Down
5 changes: 1 addition & 4 deletions Resources/Private/Fusion/Prototypes/ContentCollection.fusion
Expand Up @@ -25,10 +25,7 @@ prototype(Neos.Neos:ContentCollection) < prototype(Neos.Fusion:Tag) {
# attributes.class.@process.collectionClass >
# }
attributes {
class.@process.collectionClass = Neos.Fusion:Value {
castedArray = ${Type.isArray(value) ? value : [value]}
value = ${Array.push(this.castedArray, 'neos-contentcollection')}
}
class.@process.collectionClass = ${Array.push(value, 'neos-contentcollection')}
data-__neos-insertion-anchor = true
data-__neos-insertion-anchor.@if.onlyRenderInBackend = ${node.context.inBackend && node.context.currentRenderingMode.edit}
}
Expand Down
15 changes: 2 additions & 13 deletions Resources/Private/Fusion/Prototypes/Page.fusion
Expand Up @@ -63,19 +63,8 @@ prototype(Neos.Neos:Page) < prototype(Neos.Fusion:Http.Message) {
@position = '20'
tagName = 'body'
omitClosingTag = true
attributes.class.@process.addNeosBackendClass = Neos.Fusion:Case {
@if.onlyRenderWhenNotInLiveWorkspace = ${documentNode.context.inBackend}

classIsString {
condition = ${Type.isString(value)}
renderer = ${String.trim(value + ' neos-backend')}
}

classIsArray {
condition = ${Type.isArray(value)}
renderer = ${Array.push(value, 'neos-backend')}
}
}
attributes.class.@process.addNeosBackendClass = ${Array.push(value, 'neos-backend')}
attributes.class.@process.addNeosBackendClass.@if.onlyRenderWhenNotInLiveWorkspace = ${documentNode.context.inBackend}
}

# Content of the body tag. To be defined by the integrator.
Expand Down

0 comments on commit 2c5620c

Please sign in to comment.