Project

General

Profile

Actions

Bug #99342

closed

Field `originalResource` is null in the object fileReference of an objectstorage of an custom model, which ist parameter in an extbase-controller

Added by Dieter Porth over 1 year ago. Updated 11 months ago.

Status:
Closed
Priority:
Should have
Category:
Extbase
Target version:
-
Start date:
2022-12-12
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
11
PHP Version:
7.4
Tags:
Complexity:
Is Regression:
Sprint Focus:

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
}
}
}

```

Actions #1

Updated by Stefan Froemken 11 months 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:

https://github.com/TYPO3/typo3/blob/main/typo3/sysext/extbase/Classes/Domain/Model/FileReference.php#L44-L52

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

Actions

Also available in: Atom PDF