how is it possible to access node properties in DataSources? I want to check, if a property(“vehicleid”) is set already at the node, which is currently edited in the inspector. My aim is to set a unique id by a DataSouce, only if this is not set already.
thank you.
I thought setting a unique id(which is shown in frontend, too) for a node is a widespread use case. In example a product-id or something like that.
It’s not necessary to be able to edit this id in the inspector for my usecase, but I want to have influence on the format of the id and it should be a property of the node.
I’m sorry for my ambiguous description. I’ll try it again:
The owner of the website is a car seller, so the editors are dealing with cars.
So I created a custom nodetype named “car”, which shall have a property named “vehicleid”. This vehicleid shall be a unique id, which shall be “set automatically” at creation of every car and has not necessarily to be editable in the inspector.
My idea was to set this id by datasource. Of course only at creation of each car, so I wanted to check in the datasource, if the id is already set.
I think I can.
It shall not sound ungrateful, but I’m wondering how other developers solve this issue - I think these long node identifiers don’t look very nice in frontends and it would be fine to “adjust the format of an unique id” to each use case.
On the other hand I preferably don’t want to generate effort for my special use case (except for me ).
I just wanted to suggest an easy solution. You could probably use a custom node class and directly generate some identifier on your own on creation for example. Or use AOP. There would be ways to accomplish that, I just don’t see the reason.
See TYPO3\Neos\Service\DataSource\DataSourceInterface
/**
* Get data
*
* The return value must be JSON serializable data structure.
*
* @param NodeInterface $node The node that is currently edited (optional)
* @param array $arguments Additional arguments (key / value)
* @return mixed JSON serializable data
* @api
*/
public function getData(NodeInterface $node = null, array $arguments);
The getData method contains NodeInterface as an optional argument. Why don’t use $node for getting “vehicle” property in your data source?