Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image viewhelper do not accept FileReference #208

Closed
thorstenBorn-cosmoblonde opened this issue Oct 14, 2022 · 1 comment
Closed

Image viewhelper do not accept FileReference #208

thorstenBorn-cosmoblonde opened this issue Oct 14, 2022 · 1 comment
Assignees

Comments

@thorstenBorn-cosmoblonde

Describe the bug
Using a FileReference object as src parameter leads to an error.

Environment
TYPO3 version(s): v11.5.16
pdfviewhelpers version: v2.4.1

Steps to reproduce
Using a FileReference Object as src parameter leads to an error:
Invalid file src provided, must be either a uid, combined identifier, path/filename or implement FileInterface. ERROR: 1536560752
in ConversionService. The src parameter is handled there just for FileInterface and source path.

Expected behavior
Using the image referenced by FileReference like written in the docs:
This ViewHelper renders an image given as src. As src argument you may provide a valid TYPO3 path or an object implementing TYPO3 FAL FileInterface (e.g. File or FileReference).
Or I have not understood something correctly.

Possible solution
Extend function convertFileSrcToFileObject like this - not fully tested

if ($src instanceof FileInterface) {
    $file = $src;
} else if ($src instanceof \TYPO3\CMS\Extbase\Domain\Model\FileReference  ) {
    $file = $src->getOriginalResource()->getOriginalFile();
} else {
    try {
        $file = $this->resourceFactory->retrieveFileOrFolderObject($src);
    } catch (\Exception $e) {
        //invalid file provided
        $previousException = $e;
        $previousExceptionMessage = ' ' . $e->getMessage();
    }
}
@maechler
Copy link
Member

@thorstenBorn-cosmoblonde Thanks for this very nice bug report! I agree, the docs are not specific enough, unfortunately there are two FileReference classes:

  1. TYPO3\CMS\Core\Resource\FileReference -> implements FileInterface
  2. TYPO3\CMS\Extbase\Domain\Model\FileReference -> does not implement FileInterface

However I think it would be a nice addition to seamlessly support Extbase FileReference, so I will add support for it. In the meantime you could easily workaround this by passing the originalResource, which already implements the FileInterface, to the image ViewHelper. We are doing this in the template shipped for EXT:news, please see:

<pdf:image src="{mediaElement.originalResource}" link="{f:uri.page(pageUid: mediaElement.link)}" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants