Building a TYPO3 extension in Extbase/Fluid
Add file fields using the FAL (File Abstraction Layer): reference a single image (yourPicture)
Adding images or downloadable files to your extension should be quite easy considering that TYPO3 has everything prepared through its File Abstraction Layer (FAL). But it’s TYPO3 and so that is just a nice dream. Especially if you want to give your editors the chance to add a variable number of files without adding like 20 properties to your domain model.
But first things first: here’s what you need to know to add a single file field like e.g. a portrait photograph to the records of a database table of personnel.
File paths are relative to the root of your extension /typo3conf/ext/your_extension/
/Classes/Domain/Model/YourModel.php
<?php
/**
* yourPicture
*
* @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
*/
protected $yourPicture = NULL;
/**
* returns yourPicture
*
* @return \TYPO3\CMS\Extbase\Domain\Model\FileReference $yourPicture
*/
public function getYourPicture() {
return $this->yourPicture;
}
/**
* sets yourPicture
*
* @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $yourPicture
* @return void
*/
public function setYourPicture(\TYPO3\CMS\Extbase\Domain\Model\FileReference $yourPicture) {
$this->yourPicture = $yourPicture;
}
}
/Configuration/TCA/YourModel.php
array 'types'
››› see topic Add properties to your domain model (fields just have to be named with no further statements)
array 'columns'
›››
'your_picture' => array(
),
'exclude' => 1,
'label' => 'LLL:EXT:your_ext/Resources/Private/Language/locallang_db.xlf:tx_yourext_domain_model_yourmodel.your_picture',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'yourPicture',
array('maxitems' => 1),
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
),
),
),
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
contains a comma-separated list of allowed file extensions
/ext_tables.php and localisation files
see topic Add properties to your domain model
/ext_tables.sql
add your_picture int(11) unsigned NOT NULL default '0',
Fluid Template
<f:if condition="{yourDomain.yourPicture.originalResource.publicUrl}!=''">
{yourDomain.yourPicture.originalResource.description}
<f:image src="{yourDomain.yourPicture.originalResource.publicUrl}" alt="{yourDomain.yourPicture.originalResource.alternative}" title="{yourDomain.yourPicture.originalResource.title}" ></f:image>
{yourDomain.yourPicture.originalResource.description}
</f:if>
</f:if>