Getting the label of a datasource in Fusion

Hello,

at the moment I’m trying to understand data sources. I read through quite a lot of existing topics regarding them, but they don’t quite catch my problem.

I have almost the same use case as the manual to Custom Data Sources. I want to display authors for an article. For this I implemented a data source which receives a list with all authors. The returned result-json from the getData()-method has the id as key and the label as value.
If I access the property in fusion, only the id is displayed. Is there an easy way to access the label in fusion or do I have to implement a workaround, e.g. with writing a custom eel helper and accessing the API again? Maybe there is a way to save the data directly with additional arguments and rewriting the getData()-method?

When your authors are Nodes probably a property of type reference or references would fit better and give you immediate access to the foreign node. (Property Editor Reference — Neos CMS dev-master documentation)

In other cases data sources store what you are returning as value. So if you store a string identifier you will probably need an eel-helper to get the object behind the identifier.

Thank you for your suggestion.
No, the authors are not nodes.

I ended up writing an eel-helper which has an array of the ids as parameter and calls the API again to save the names/label.

But just to be clear if I use this slightly modified code from the manual, only the $user->id would be saved in the property calling the data source?

public function getData(NodeInterface $node = null, array $arguments = [])
    {
        $options = [];
        foreach ($someUserCollection as $user) {
            $options[$user->id] = ['label' => $user->label];
        }
        return $options;
    }

I personally would add a key value in addition to label. There is a fallback to the array keys (as far as i know and the example relies on that) but i prefer to be explicit.

$options[] = ['label' => $user->label, 'value' => $user->id];

https://neos.readthedocs.io/en/stable/References/PropertyEditorReference.html#property-type-string-array-string-selectboxeditor-dropdown-select-editor

There are some more informations about the features DataSources support.

1 Like