TCA Änderungenin TYPO3 6.2
am Beispiel einer Erweiterung der News Extension
bisherige Situation• Erweiterungen in ext_tables.php
• Kein Code Cache
• ext_tables.php wird zur Laufzeit mehrfach eingelesen
• Unübersichtlich. Änderungen können sich leicht gegenseitig überschreiben.
Configuration/TCA/Overrides
• Eingeführt mit TYPO3 6.2
• Beliebiger Dateiname
• Beliebig viele Dateien möglich
• Best practice:<extkey>/Configuration/TCA/Overrides/<tablename>.php
Vorteile
• klar definierte Stelle, wo Änderungen passieren
• TCA Änderungen landen im Code Cache
• ext_tables.php wird entschlackt
• Performance Gewinn im Backend wenn alle Extensions das Feature nutzen
Beispiele• Systemextensions
• css_styled_content
• saltedpasswords
• felogin
• news_exampleextension
News erweitern
Neue News Typen und ein neues Feld
Struktur• Extbase Verzeichnisstruktur
• Resources/Private/extend-news.txt
• enthält Pfade zu den Dateien, die erweitert werden sollen
• Ohne Dateiendung .php
• Beispiel: Domain/Model/News
Configuration/TCA/Overrides/ tx_news_domain_model_news.php
<?php defined('TYPO3_MODE') or die();
use \TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
$tempColumns = Array ( 'authorprofile' => Array ( 'exclude' => 1, 'label' => 'LLL:EXT:news_exampleextension/Resources/Private/Language/
locallang_db.xlf:tx_newsexampleextension_domain_model_news. authorprofile',
'config' => array( 'type' => 'group', 'internal_type' => 'db', 'allowed' => 'pages', 'foreign_table' => 'pages', 'size' => 1, 'minitems' => 0, 'maxitems' => 1, 'wizards' => array( 'suggest' => array( 'type' => 'suggest', ), ), ), ), );
if (ExtensionManagementUtility::isLoaded('news')) {
// register new news types $GLOBALS['TCA']['tx_news_domain_model_news']['types']['blogText'] =
$GLOBALS['TCA']['tx_news_domain_model_news']['types']['0'];
$GLOBALS['TCA']['tx_news_domain_model_news']['types']['blogImage'] = $GLOBALS['TCA']['tx_news_domain_model_news']['types']['0'];
// add individual type icons $GLOBALS['TCA']['tx_news_domain_model_news']['ctrl']['typeicons']['blogText'] =
ExtensionManagementUtility::extRelPath('news_exampleextension') . 'Resources/Public/Icons/news_domain_model_news_blogText.png';
$GLOBALS['TCA']['tx_news_domain_model_news']['ctrl']['typeicons']['blogImage'] = ExtensionManagementUtility::extRelPath('news_exampleextension') . 'Resources/Public/Icons/news_domain_model_news_blogImage.png';
// add author profile only to above registered news types ExtensionManagementUtility::addTCAcolumns(
'tx_news_domain_model_news', $tempColumns
);
ExtensionManagementUtility::addToAllTCAtypes( 'tx_news_domain_model_news', 'authorprofile;;;;1-1-1', 'blogText,blogImage', 'after:related_from'
); }
Configuration/TSconfig/Page/mod.tx_news_domain_model_news.txt
TCEFORM.tx_news_domain_model_news.type.addItems {
blogText = LLL:EXT:news_exampleextension/Resources/Private/Language/ locallang_db.xlf:tx_newsexampleextension_domain_model_news.type.blogText
blogImage = LLL:EXT:news_exampleextension/Resources/Private/Language/ locallang_db.xlf:tx_newsexampleextension_domain_model_news.type.blogImage
}
ext_localconf.php<?php if (!defined ('TYPO3_MODE')) { die ('Access denied.'); }
if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('news')) { // add page TSConfig which extends the news types \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig(
'<INCLUDE_TYPOSCRIPT: source="FILE:EXT:' . $_EXTKEY . ‚/Configuration/TSconfig/Page/mod.tx_news_domain_model_news.txt">'
); }
Classes/Domain/Model/AbstractNewsBlogItem.php<?php namespace KWS\NewsExampleextension\Domain\Model;
/** * News model for default news * * @package TYPO3 * @subpackage tx_newsexampleextension */ abstract class AbstractNewsBlogItem extends \Tx_News_Domain_Model_News { /** * @var integer */ protected $authorprofile;
/** * Set author profile * * @param integer $authorprofile author profile * @return void */ public function setAuthorprofile($authorprofile) { $this->authorprofile = $authorprofile; }
/** * Get author profile * * @return integer */ public function getAuthorprofile() { return $this->authorprofile; } }
Classes/Domain/Model/NewsBlogText.php
<?php namespace KWS\NewsExampleextension\Domain\Model;
/** * News model for default news * * @package TYPO3 * @subpackage tx_newsexampleextension */ class NewsBlogText extends AbstractNewsBlogItem { }
Configuration/TypoScript/setup.txt
config.tx_extbase.persistence.classes { Tx_News_Domain_Model_News { subclasses { blogText = KWS\NewsExampleextension\Domain\Model\NewsBlogText blogImage = KWS\NewsExampleextension\Domain\Model\NewsBlogImage } }
KWS\NewsExampleextension\Domain\Model\NewsBlogText { mapping { recordType = blogText tableName = tx_news_domain_model_news } }
KWS\NewsExampleextension\Domain\Model\NewsBlogImage { mapping { recordType = blogImage tableName = tx_news_domain_model_news } } }
Configuration/TCA/Overrides/ tt_content.php
<?php if (!defined('TYPO3_MODE')) { die ('Access denied.'); }
use \TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
$_EXTKEY = $GLOBALS['_EXTKEY'] = 'news_exampleextension';
ExtensionManagementUtility::addStaticFile( $_EXTKEY, 'Configuration/TypoScript', 'Additional types for EXT:news'
);
Fluid Template• {newsItem.type}
• enthält neue Typen
• blogText
• blogImage
• {newsItem.authorprofile}
• enhält uid der Seite
Ressourcen
• https://forge.typo3.org/issues/57942
• http://ab-softlab.tumblr.com/post/90851249969/tca-manipulation-in-typo3-6-2
• https://github.com/peterkraume/news_exampleextension
Vielen Dank
@Cybersmog
http://de.slideshare.net/pk77
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.