1
votes

I have in my TYPO3 an object called Location where I store informations about a city, including a pdf file. In the backend I can upload a pdf without problem, but when I try to display it, I get NULL. The value of 'pdf' in the database is not NULL, but when I debug <f:debug>{location}</f:debug> I get pdf => NULL !!!

Here is my TCA/LOCATION :

$GLOBALS['TCA']['tx_locations_domain_model_location'] = array(
    'ctrl' => $GLOBALS['TCA']['tx_locations_domain_model_location']['ctrl'],

....
    'columns' => array(
...
        'pdf' => array(
            'exclude' => 1,
            'label' => 'LLL:EXT:locations/Resources/Private/Language/locallang_db.xlf:tx_locations_domain_model_location.pdf',
            'config' => array (
                'type' => 'group',
                'internal_type' => 'file',
                'allowed' => $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],
                'max_size' => $GLOBALS['TYPO3_CONF_VARS']['BE']['maxFileSize'],
                'uploadfolder' => 'uploads/pics',
                'show_thumbs' => 1,
                'size' => 1,
                'minitems' => 0,
                'maxitems' => 1
            )
        ),
...

The Getter and Setter should be fine in typo3conf/ext/locations/Classes/Domain/Model/Location.php :

/**
 * Returns the pdf
 *
 * @return \TYPO3\CMS\Extbase\Domain\Model\FileReference $pdf
 */
public function getPdf() {
    return $this->pdf;
}

/**
 * Sets the pdf
 *
 * @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $pdf
 * @return void
 */
public function setPdf(\TYPO3\CMS\Extbase\Domain\Model\FileReference $pdf) {
    $this->pdf = $pdf;
}

You can see the debug gives pdf=> NULL from below:

See here

My pdf column is not empty :

See here

Did I miss something ??

UPDATE : After the answer of Pavin, I can see something in PDF, but I can't get the name of the file in href tag , maybe I need to change something after the new answer. I can see things changed in the Database, the pdf field now is boolean. that's why maybe I get pdf0.originalResource NULL, but in the backend I can upload files and see then after save and refresh !!!:

enter image description here

        <p><f:translate key="tx_locations_domain_model_location.downloadpdf" /> <a class="download" target="_blank" title="Initiates file download" href="{location.pdf.originalResource.publicUrl}"><f:translate key="tx_locations_domain_model_location.here" />..</a></p>

enter image description here

UPDATE 2

my new Model/Location.php

/**
     * pdf
     *
     * @var string
     */
    protected $pdf = NULL;

...
/**
     * Returns the pdf
     *
     * @return string $pdf
     */
    public function getPdf() {
        return $this->pdf;
    }

    /**
     * Sets the pdf
     *
     * @param string $pdf
     * @return void
     */
    public function setPdf($pdf) {
        $this->pdf = $pdf;
    }

My TCA/Location.php

'pdf' => array(
            'exclude' => 1,
            'label' => 'LLL:EXT:locations/Resources/Private/Language/locallang_db.xlf:tx_locations_domain_model_location.pdf',
            'config' => array (
                'type' => 'group',
                'internal_type' => 'file',
                'allowed' => $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],
                'max_size' => $GLOBALS['TYPO3_CONF_VARS']['BE']['maxFileSize'],
                'uploadfolder' => 'uploads/pics',
                'show_thumbs' => 1,
                'size' => 1,
                'minitems' => 0,
                'maxitems' => 1
            )
        ),
2

2 Answers

1
votes

You can use below TCA configuration for Doc types records. also add Getter and Setter methods in modle file.

'pdf' => array(
    'exclude' => 0,
    'label' => 'LLL:EXT:ext_key/Resources/Private/Language/locallang_db.xlf:label_key.files',
    'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
        'pdf',
        array('minitems' => 0,'maxitems' => 10),
        'pdf,doc,docx'
    ),
),

For Model.php files.

    /**
     * pdf
     *
     *@var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>
     */
    protected $pdf;

initStorageObjects Methods :

    protected function initStorageObjects() {
        $this->files = new ObjectStorage();
        parent::initializeObject();
    }

Getter And Setter Method:

   /**
     * Returns the pdf
     *
     * @return ObjectStorage
     */
    public function getPdf() {
        return $this->pdf;
    }

    /**
     * Sets the pdf
     *
     */
    public function setPdf($pdf) {
        $this->pdf = $pdf;
    }

See attached image for pdf name. Please add pdf title. For Pdf title you can use {location.pdf.title} enter image description here

0
votes

You use group as the type for saving the file in the TCA, so the property $pdf in your model must be string and not \TYPO3\CMS\Extbase\Domain\Model\FileReference

FileReference only work for FAL (File Abstraction Layer)