1

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
            )
        ),
Heinz Schilling
  • 2,177
  • 4
  • 18
  • 35

2 Answers2

1

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

Pravin Vavadiya
  • 3,195
  • 1
  • 17
  • 34
  • This didn't work, I don't even see anymore the pdf uploader in the Backend – ali chouchen Apr 12 '17 at 09:01
  • I updated my Location.php as you said, it didn't work, now I get in the BackEnd "Unknown type: " !! – ali chouchen Apr 12 '17 at 09:38
  • In **initStorageObjects** methos like $this->pdf = new ObjectStorage(); – Pravin Vavadiya Apr 12 '17 at 09:43
  • I don't have Model.php, Maybe you mean Model.phpt or Model/Location.php ? Anyway I tried them both and didn't work, in the frontend I get alwayspdf=>NULL – ali chouchen Apr 12 '17 at 09:44
  • After add this changes you need to once install / un-install extension. you did it? – Pravin Vavadiya Apr 12 '17 at 09:47
  • (See my UPDATE) I reactivated the exension (because somehow I can't download it), but I see the upload imterface changed in my BE (that's fine), and I can't get the filename with the new changes, I used before **href="{location.pdf.originalResource.publicUrl}"** – ali chouchen Apr 12 '17 at 10:12
  • This I did, but in the location table, the pdf row is 1 or 0, how can I have the file name in clic to download ?? – ali chouchen Apr 12 '17 at 10:28
  • I see the same thing as you in BE, and it is ok, but my problem was always in the front end to get the name of the file, before pdf was NULL, now pdf is not NULL but location.pdf.originalResource is NULL – ali chouchen Apr 12 '17 at 10:31
  • in Location Table pdf value always 0 and 1. if you have add pdf then it's 1 othervies 0. You can use **Download**. also in template file if you need display pdf name then add **{location.pdf.title}**. if you have added pdf title then it's display – Pravin Vavadiya Apr 12 '17 at 10:32
  • You can see my second debug picture, originalResource is NULL and there is no title proprtie. – ali chouchen Apr 12 '17 at 10:36
  • Can you come to chat please ? with send you more screenshots, better then drop them all in the post – ali chouchen Apr 12 '17 at 10:38
  • Yes You right **originalResource** always display null. But if you can use **{location.pdf.originalResource.publicUrl}** in template file. after check frontend and inspect element. pdf path is alrady asign in href tag – Pravin Vavadiya Apr 12 '17 at 10:42
  • I checked, it is NULL :/ also debug **{location.pdf.originalResource.publicUrl}** gives NULL !!! – ali chouchen Apr 12 '17 at 10:44
  • Okay. in Location table pdf fields data type set int. after extension install / un-insatll and check now – Pravin Vavadiya Apr 12 '17 at 10:46
  • For both **varchar** or **int** it is the same, **location.pdf.originalResource** is NULL :/ – ali chouchen Apr 12 '17 at 11:24
0

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)

Dimitri L.
  • 4,499
  • 1
  • 15
  • 19