Bug #99342
closedField `originalResource` is null in the object fileReference of an objectstorage of an custom model, which ist parameter in an extbase-controller
0%
Description
My controller will reciece an object TaskAssignement
. The object contains in the field files
a storageObject, which contains a list of filereferences.
The field originalResource
is null.
I would expect, that the field originalResource
ist filled with the object TYPO3\CMS\Core\Resource\FileReference
and in related object.
To fix this bug, I had to use the folowing method in my controller.
```
/**
* @param TaskAssignment $taskAssignment
*
* @return void
*/
protected function bugFixTYPO3ForMissingObjectsInFileRepresentation(TaskAssignment $taskAssignment): void
{
/** @var ObjectStorage $listFilesStorage /
$listFilesStorage = $taskAssignment->getFiles();
if ($listFilesStorage !== null) {
$listFilesStorage = $listFilesStorage->toArray();
/* @var FileReference $fileRef */
foreach ($listFilesStorage as $fileRef) {
$fileRef->setOriginalResource($fileRef->getOriginalResource());
$fileRef->getOriginalResource()->getProperties(); // result is not used. only the build of merged properties are triggerd
}
}
}
```
Updated by Stefan Froemken over 1 year ago
- Status changed from New to Closed
- Assignee set to Stefan Froemken
Hello Dieter,
thank you for reporting that issue. If you debug extbase FileReference, the originalResource property is initially always null. With first call of getOriginalResource() or within Fluid "record.originalResource" the originalResource property will be set automatically:
So there is no need to get originalResource and set it afterwards.
You can just call $fileRef->getOriginalResource()->getProperties(); to retrieve the merged properties, if needed. Also there is no need to call toArray() for a simple foreach. The ObjectStorage implements an ArrayIterator which allows looping through the storage.
I will close the ticket now. If you feel this is the wrong decision, let me know, and I will re-open it.
Stefan