Variable array key

Hello,

I am trying to link to my plugin from another page.

The plugin is also loaded multiple times in that page, so I am using namespaces with the node identifier.

Thus, following the documentation example, I end up making the following URI in fusion:

myLink = Neos.Neos:NodeUri {
    node = ${node}
    absolute = true
    additionalParams = ${{'--1d6f2701-95b4-4c84-91f2-a065bdc7be46': {'@package': 'vendor.site.package', '@controller':'myCont', '@action': 'myAct'}}}
}

Works well, for the specified node, but now I need to take it to its final form and make the identifier dynamic, any idea how I can do that ?

Attempt 1:

// The following does NOT work, it generates an array with key 'myVar', assuming a context variable myVar exists.
additionalParams = ${{myVar: {'@package': 'vendor.site.package', '@controller':'myCont', '@action': 'myAct'}}}

Attempt 2:

// The following does NOT work either, it results in an empty URI
additionalParams = ${{node.identifier: {'@package': 'vendor.site.package', '@controller':'myCont', '@action': 'myAct'}}}

Attempt 3 (by Rene):

// The following does NOT work either, it results in an empty URI
additionalParams  = Neos.Fusion:RawArray {
    node.identifier = Neos.Fusion:RawArray {
        '@package' = 'vendor.site.plugin'
        '@controller' = 'myCont'
        '@action' = 'myAct'
    }
}

Thanks in advance !

Well, since noone answered, I went ahead and overkilled this little problem with a fusion object. I’m sharing the solution, but please don’t close this topic, I would be very interested to hear a native Fusion solution.

Classes/Fusion/ArrayIndexImplementation.php

namespace Vendor\Site\Package\Fusion;

use Neos\Flow\Annotations as Flow;
use Neos\Fusion\FusionObjects\AbstractFusionObject;

class ArrayIndexImplementation extends AbstractFusionObject
{
    /**
     * Render the single-index array as defined in fusion.
     *
     * @return array
     */
    public function evaluate()
    {
        $key = $this->fusionValue('key');
        $value = $this->fusionValue('value');

        return [
            $key => $value,
        ];
    }
}

Private/Fusion/Prototypes/ArrayIndex.fusion

prototype(Vendor.Site.Package:ArrayIndex) {
    @class = 'Vendor\\Site\\Package\\Fusion\\ArrayIndexImplementation'

    key = '-set-by-the-user-'
    value = '-set-by-the-user-'
}

And with these, my URI builder becomes this:

myLink = Neos.Neos:NodeUri {
    node = ${node}
    absolute = true
    additionalParams = Vendor.Site.Package:ArrayIndex {
        key = ${'--' + node.identifier}
        value = ${{'@package': 'vendor.site.package', '@controller':'myCont', '@action': 'myAct'}}
    }
}

And with these, my URI builder becomes this:

myLink = Neos.Neos:NodeUri {
    node = ${node}
    absolute = true
    additionalParams = Vendor.Site.Package:ArrayIndex {
        key = ${'--' + node.identifier}
        value = ${{'@package': 'vendor.site.package', '@controller':'myCont', '@action': 'myAct'}}
    }
}

This will work for an array with a single key. If you want to have more than one key/value pair, this won’t work, or am i wrong? So this will only work in your one special case.

Yes, you’re right, I am already aware of this, that’s why I have a feeling there must be a better way to do this.

In fact I had a case facing this problem, which can easily be solved by Array.join EEL Helper. Can’t find it now for some reason …