Urs
Urs

Reputation: 5122

Display Extbase FileReference with Fluid

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>

Upvotes: 4

Views: 5015

Answers (1)

Jost
Jost

Reputation: 5840

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).

Upvotes: 4

Related Questions