4
votes

In an extbase extension, I have a FileReference Object. It was created with extension_builder originally. From The Model:

/**
 * apprenticeshipDocument
 *
 @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
 */
protected $apprenticeshipDocument = NULL;

etc.

In the frontend, <f:debug>{institution.apprenticeshipDocument}</f:debug> gives me this:

Extbase Var Dump

First Thing: originalResource is missing.

Second: When calling {institution.apprenticeshipDocument.uidLocal} directly, the value is NULL! Although it's said to be 450 above.

Third: Let's say we could get uidLocal, which corresponds to the uid in sys_file.

The googlable solution:

<f:link.page pageUid="{f:uri.image(src:450)}" target="_blank">Text</f:link.page>

doesn't point to the PDF file itself, but to a rendered GIF of the PDF. All I want to do is output the path to the file (sys_file.identifier) in a link... there must be a way, mustn't it?

EDIT: Solution provided by Jost:

<f:if condition="{institution.apprenticeshipDocument}">
    <li>
    <f:link.page pageUid="{institution.apprenticeshipDocument.originalResource.publicUrl}" target="_blank">Text</f:link.page>
    </li>
</f:if>
1
Maybe related to forge.typo3.org/issues/48965 ? But I'm on 6.2.12, where the patch seems to be includedUrs
Ah just found forum.typo3.org/index.php/t/198281 will look into thatUrs
originalResource is lazy-loaded, so it is correct to be NULL. Just access it. I believe you can also access it and then do the f:debug to see all its fields. One of them will be originalFile, which is also lazy-loaded.Jost
Reason for uidLocal not being accessible is probably that there is no getter for it, so fluid can't read it. To link the file, I usually use the v:link.typolink ViewHelper from EXT:vhs, which you can use like this: <v:link.typolink configuration="{parameter: 'file:{variableContainingUid}'}>Linktext</v:link.typoscript>. Alternatively, you could use {institution.apprenticeshipDocument.originalResource.publicUrl} to get the URL (not sure about the exact name).Jost
Try to use the publicUrl-property of the file (or reference) instead - there is a getter for it in the fileInterface, so both file and file reference have that property. Also, there are more properties available, that you can't see in the debug output, mostly metadata - they are accessed using a magic getter.Jost

1 Answers

4
votes

Files and file references behave a bit different in fluid than usual:

  1. They are lazy-loaded, so the originalResource (Extbase file reference) and originalFile (Core file reference) values are NULL before the first access to them. But you can just access them as usual.
  2. The value uidLocal of an extbase file reference can't be accessed because there is no getter for it (as of TYPO3 6.2.12 and 7.2).
  3. To get the url of a file, use its publicUrl attribute, or use the ViewHelper v:link.typolink from EXT:vhs, like this:

    <v:link.typolink configuration="{parameter: 'file:{uid}'}>
        Linktext
    </v:link.typolink>
    

    uid is the id of the file in this case.

  4. Many properties of files (especially metadata-properties) are not saved as normal object attributes, but are internally saved into an associative array and then fetched using a magic getter. They are also lazy-loaded. Thus, they usually don't show up as separate properties in variable dumps, and may be not set at all or NULL (same as above).