#97689Resolve file relation on JsonView configuration
Description
I recently created a headless project. For the project i used the news extension as well. With the help of the PSR-14, i got the news entries on my listener class. I wanted to convert the object to array because headless does not support extbase object, only json. I managed to convert everything to array with the following configuration:
$this->view->setConfiguration([
'news' => [
'_descendAll' => [
'_recursive' => ['categories', 'falMedia', 'contentElements', 'tags']
],
]
]);
Everything worked fine until i saw the falMedia object. It resolved the sys_file_reference, meaning it found the file, but it didnt retrieve the object, instead it returned the UID of the file. This is what i got:
falMedia": {
"0000000018019f7e000000007283656b": {
"alternative": "",
"description": "",
"fileUid": 8,
"link": "",
"pid": 37,
"showinpreview": 0,
"title": "",
"uid": 93
}
},
The UID is the sys_file_reference id and the fileUid is the file id in the sys_file table.
AFAIK there is not a function implemented that does just that (i looked inside the JsonView class) so it would be great if that can be possible in the future
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
Files 1
History 1
-
Georg Ringer commented and changed status
NewClosed <span data-processor="relativetime" data-value="2026-10-09T17:45:45+00:00" > 10/09/26, 17:45 </span>
Thanks for the report! I had a look at this on main.
The
JsonViewonly renders properties which are declared in the class and have a matching getter (ObjectAccess::getGettablePropertyNames()). For files and file references most of the interesting data (public URL, merged metadata like title and alternative) is only available through getters without a matching property, which is why you only get the raw reference data.Instead of adding special handling for FAL to the core, this can already be solved today in two ways:
1. Extend the JsonView
JsonView::transformObject()is protected, so a custom view can render files the way the project needs them:Use it in the controller:
The existing configuration with
_descend/_recursiveonfalMediathen renders the file data.2. Convert the files before assigning them
If the data is prepared in a PSR-14 listener anyway, the file references can be converted to plain arrays right there. Arrays are rendered by the
JsonViewas they are:As both options work without changes to the core and every project needs a different set of file data (e.g. processed images in different sizes), I would like to close this issue. Please let me know if this does not cover your use case.