Bug #99442
openFileRepository::findByRelation() works differently in FE or other contexts and will not return the file reference objects in CLI context
0%
Description
The problem is not only that the function behaves differently in FE and CLI but also that this is not reflected in the description (PHPDoc) and in the documentation. (Also, I assume it works in BE, but not in CLI).
I don't know why this relatively lowlevel function should behave differently based on context (and if this is still correct).
Documentation:
Getting Referenced files
This snippet shows how to retrieve FAL items that have been attached to some other element, in this case the "media" field of the "pages" table:
EXT:some_extension/Classes/SomeClass.php
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Resource\FileRepository;
$fileRepository = GeneralUtility::makeInstance(FileRepository::class);
$fileObjects = $fileRepository->findByRelation('pages', 'media', $uid);
Reproduce¶
Tested with TYPO3 v11.5.21
It is possible to reproduce with this extension: https://github.com/sypets/sypets_example_findbyrelation_cli
1. Create a field of type "inline" with file objects in Flexform of a content element
2. In a CLI command process the Flexform settings and try to get the file object (see code below)
3. Run command on command line. Try to process the $fileObjects
command: (extends Symfony\Component\Console\Command\Command):
use TYPO3\CMS\Core\Resource\FileRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
// ....
$fileRepository = GeneralUtility::makeInstance(FileRepository::class);
// ....
// this will return false
$fileObjects = $this->fileRepository->findByRelation('tt_content', 'pi_flexform', $uid);
Updated by Sybille Peters almost 2 years ago
- Related to Bug #61344: findByRelation() does not work since 6.2.4 added
Updated by Sybille Peters almost 2 years ago
It is possible to reproduce with this extension: https://github.com/sypets/sypets_example_findbyrelation_cli
Updated by Claus Due 5 months ago
- Related to Bug #104331: \TYPO3\CMS\Core\Resource\FileRepository::findByRelation incapable of handling FAL relations in FlexForm in BE context added