Typo3 FAL (file abstract layer) Tabelle sys_file_reference um eigenes Feld erweitern

Samstag, 13. Juni 2015

Möchte man ein eigenes Feld zu der Tabelle sys_file_reference hinzufügen, macht man dazu am Besten eine kleine Extension. Die entscheidenden Stellen sind:

Datei: ext_tables.php

$tempColumns = Array (
  "imgvariants" => Array (    
    'exclude' => 1,
      'label' => 'Dropdown-Beispiel',
      'config' => array(
        'type' => 'select',
        'items' => array(
          array(
            'Dropdown-Label 1',
            '0',
          ),
          array(
            'Dropdown-Label 2',
            '1',
          ),
          array(
            'Dropdown-Label 3',
            '2',
          ),
        ),
        'default' => '0',
      ),
  ),
);
 
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns("sys_file_reference",$tempColumns,1);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('sys_file_reference', 'imgvariants');
 
$TCA['sys_file_reference']['palettes']['imageoverlayPalette']['showitem'] .= ',--linebreak--,imgvariants,--palette--;LLL:EXT:t3pimper/locallang_db.xml:tt_content.imgvariants;';
$TCA['sys_file_reference']['types']['1']['showitem'] .= ',--linebreak--,imgvariants,--palette--;LLL:EXT:t3pimper/locallang_db.xml:tt_content.imgvariants;';

Datei: Typoscript setup.txt

config.tx_extbase{
  persistence{
    classes{
 
      TYPO3\CMS\Extbase\Domain\Model\FileReference {
        subclasses {
           Tx_T3pimper_FileReference = NNGrad\T3pimper\Domain\Model\FileReference
          }
      }
 
      NNGrad\T3pimper\Domain\Model\FileReference {
        mapping {
          tableName = sys_file_reference
        }
      }
 
    }
  }
}

Datei: Typoscript setup.txt

config.tx_extbase{
  persistence{
    classes{
 
      TYPO3\CMS\Extbase\Domain\Model\FileReference {
        subclasses {
           Tx_T3pimper_FileReference = NNGrad\T3pimper\Domain\Model\FileReference
          }
      }
 
      NNGrad\T3pimper\Domain\Model\FileReference {
        mapping {
          tableName = sys_file_reference
        }
      }
 
    }
  }
}

Datei: Classes/Domain/Model/FileReference.php

<?php
namespace NNGrad\T3pimper\Domain\Model;
 
class FileReference extends \TYPO3\CMS\Extbase\Domain\Model\FileReference {
 
  /**
   * imgvariants
   *
   * @var integer
   */
  protected $imgvariants = 0;
 
 
  /**
   * Returns the imgvariants
   *
   * @return integer $imgvariants
   */
  public function getImgvariants() {
    return $this->imgvariants;
  }
 
  /**
   * Sets the imgvariants
   *
   * @param integer $imgvariants
   * @return void
   */
  public function setImgvariants($imgvariants) {
    $this->imgvariants = $imgvariants;
  }
 
}
 
?>

Datei: Fluid Template

{image.imgvariants}