neos / neos-development-collection

The unified repository containing the Neos core packages, used for Neos development.
https://www.neos.io/
GNU General Public License v3.0
260 stars 221 forks source link

BUG? Fusion `value` not accessible in `@if` for `@process` #4879

Open mhsdesign opened 8 months ago

mhsdesign commented 8 months ago

@if is evaluated before the value is pushed into the context. It is to be discussed if this is intended behaviour or not:

root = 'abc'
root.@process.convert = Neos.Fusion:Value {
  @if.is = ${value == 'abc'}
  value = ${123}
}

The logic lies in https://github.com/neos/neos-development-collection/blob/336a658ee5e6be98b3b034a4c04773b59fde513b/Neos.Fusion/Classes/Core/Runtime.php#L855. Locally i could fix it by moving the pushContext first.

but changing this behaviour would "break" this:

root = "outer"
root.@process.outerProcess = Neos.Fusion:Value {
  @if.noAccessToValue = ${value}
  value = "inner"
  value.@process.inner {
    @if.accessToOuterValue = ${value} // value is outer
    expression = "foo"
  }
}
kitsunet commented 8 months ago

I am pretty sure there was a good reason for doing it this way. You shoulnd't if a processor anyway but rather use a control structure on the replacement ala value = ${value == 'abc' ? 123 : value}. While I guess in this special case of processors it could make sense to have the value already I find in normal rendering cases you would want to first evaluate if before doing anything on the fusion object in question.

mhsdesign commented 8 months ago

in my specific case i just wanted to quickly notate this:

# resource:// or http://
resourceUri = 'resource://Foo.Bar'
resourceUri.@process.convertResourceStreamWrapper = Neos.Fusion:ResourceUri {
  @if.isResourceStreamWrapper = ${String.indexOf(value, 'resource://') == 0}
  path = ${value}
}

in the end i build a full blown prototype:

prototype(Neos.Neos:Core.ImageSource) < prototype(Neos.Fusion:Component) {
    path = ''
    renderer = Neos.Fusion:Case {
        resourcePath {
            condition = ${String.indexOf(props.path, 'resource://') == 0}
            renderer = Neos.Fusion:ResourceUri {
                path = ${props.path}
            }
        }
        default {
            condition = true
            renderer = ${props.path}
        }
    }
}

But i would be also fine with closing this as not planned, as my above prosed fusion config is not super easy to decipher i guess. So to quickly move forward let met now if i should close this or well keep it open until we find the time to discuss this.