Hallo,
ich versuche gerade, mir die neue Category API etwas genauer anzuschauen, und scheitere schon im ersten Schritt.
Und zwar möchte ich eine ganz simple Extension erstellen, deren Model Items im Backend dann kategorisierbar sind. Mit dem Extension Builder kickstarte ich eine einfache Extension mit einem Model 'Books', ohne Repository, Controller oder Plugin. Das Model sieht so aus:
<?php
namespace Moody\MoodyBooks\Domain\Model;
/**
*
*
* @package moody_books
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*
*/
class Book extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
/**
* title
*
* @var \string
* @validate NotEmpty
*/
protected $title;
/**
* description
*
* @var \string
*/
protected $description;
/**
* categories
*
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\Category>
*/
protected $categories;
/**
* __construct
*
* @return Book
*/
public function __construct() {
//Do not remove the next line: It would break the functionality
$this->initStorageObjects();
}
/**
* Initializes all ObjectStorage properties.
*
* @return void
*/
protected function initStorageObjects() {
// empty
}
/**
* Returns the title
*
* @return \string $title
*/
public function getTitle() {
return $this->title;
}
/**
* Sets the title
*
* @param \string $title
* @return void
*/
public function setTitle($title) {
$this->title = $title;
}
/**
* Returns the description
*
* @return \string $description
*/
public function getDescription() {
return $this->description;
}
/**
* Sets the description
*
* @param \string $description
* @return void
*/
public function setDescription($description) {
$this->description = $description;
}
/**
* Adds a Category
*
* @param \TYPO3\CMS\Extbase\Domain\Model\Category $category
* @return void
*/
public function addCategory(\TYPO3\CMS\Extbase\Domain\Model\Category $category) {
$this->categories->attach($category);
}
/**
* Removes a Category
*
* @param \TYPO3\CMS\Extbase\Domain\Model\Category $categoryToRemove The Category to be removed
* @return void
*/
public function removeCategory(\TYPO3\CMS\Extbase\Domain\Model\Category $categoryToRemove) {
$this->categories->detach($categoryToRemove);
}
/**
* Returns the categories
*
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\Category> $categories
*/
public function getCategories() {
return $this->categories;
}
/**
* Sets the categories
*
* @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\Category> $categories
* @return void
*/
public function setCategories(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $categories) {
$this->categories = $categories;
}
}
?>
In der Property 'categories' binde ich Elemente vom Typ \TYPO3\CMS\Extbase\Domain\Model\Category ein.
nun möchte ich, dass diese Kategorien im Backend auch als eigener Tab ausgegeben werden, dazu rufe ich in der ext_tables.php zum Schluss die Funktion makeCategorizable auf:
<?php
if (!defined('TYPO3_MODE')) {
die ('Access denied.');
}
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'Configuration/TypoScript', 'Moody Books');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addLLrefForTCAdescr('tx_moodybooks_domain_model_book', 'EXT:moody_books/Resources/Private/Language/locallang_csh_tx_moodybooks_domain_model_book.xlf');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tx_moodybooks_domain_model_book');
$TCA['tx_moodybooks_domain_model_book'] = array(
'ctrl' => array(
'title' => 'LLL:EXT:moody_books/Resources/Private/Language/locallang_db.xlf:tx_moodybooks_domain_model_book',
'label' => 'title',
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'cruser_id' => 'cruser_id',
'dividers2tabs' => TRUE,
'versioningWS' => 2,
'versioning_followPages' => TRUE,
'origUid' => 't3_origuid',
'languageField' => 'sys_language_uid',
'transOrigPointerField' => 'l10n_parent',
'transOrigDiffSourceField' => 'l10n_diffsource',
'delete' => 'deleted',
'enablecolumns' => array(
'disabled' => 'hidden',
'starttime' => 'starttime',
'endtime' => 'endtime',
),
'searchFields' => 'title,description,',
'dynamicConfigFile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY) . 'Configuration/TCA/Book.php',
'iconfile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath($_EXTKEY) . 'Resources/Public/Icons/tx_moodybooks_domain_model_book.gif'
),
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::makeCategorizable(
$_EXTKEY,
'tx_moodybooks_domain_model_book',
'categories',
array()
);
?>
Wenn ich nun die Extension installiere und ein neues Element vom Typ "Book" anlege, ist weit und breit keine Kategorisierung zu sehen. Die Funktion 'makeCategorizable' sollte ja eigentlich automatisch das TCA für meine Extension so erweitern, dass die Kategorisierungsfunktion angezeigt wird. Wenn ich mir aber über das Konfigurationsmodul den TCA für meine Extension anschaue, dann ist dieser unverändert so, wie ihn mir der Extensionbuilder ausgespuckt hat.
<?php
if (!defined ('TYPO3_MODE')) {
die ('Access denied.');
}
$TCA['tx_moodybooks_domain_model_book'] = array(
'ctrl' => $TCA['tx_moodybooks_domain_model_book']['ctrl'],
'interface' => array(
'showRecordFieldList' => 'sys_language_uid, l10n_parent, l10n_diffsource, hidden, title, description',
),
'types' => array(
'1' => array('showitem' => 'sys_language_uid;;;;1-1-1, l10n_parent, l10n_diffsource, hidden;;1, title, description,--div--;LLL:EXT:cms/locallang_ttc.xlf:tabs.access,starttime, endtime'),
),
'palettes' => array(
'1' => array('showitem' => ''),
),
'columns' => array(
'sys_language_uid' => array(
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.language',
'config' => array(
'type' => 'select',
'foreign_table' => 'sys_language',
'foreign_table_where' => 'ORDER BY sys_language.title',
'items' => array(
array('LLL:EXT:lang/locallang_general.xlf:LGL.allLanguages', -1),
array('LLL:EXT:lang/locallang_general.xlf:LGL.default_value', 0)
),
),
),
'l10n_parent' => array(
'displayCond' => 'FIELD:sys_language_uid:>:0',
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.l18n_parent',
'config' => array(
'type' => 'select',
'items' => array(
array('', 0),
),
'foreign_table' => 'tx_moodybooks_domain_model_book',
'foreign_table_where' => 'AND tx_moodybooks_domain_model_book.pid=###CURRENT_PID### AND tx_moodybooks_domain_model_book.sys_language_uid IN (-1,0)',
),
),
'l10n_diffsource' => array(
'config' => array(
'type' => 'passthrough',
),
),
't3ver_label' => array(
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.versionLabel',
'config' => array(
'type' => 'input',
'size' => 30,
'max' => 255,
)
),
'hidden' => array(
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.hidden',
'config' => array(
'type' => 'check',
),
),
'starttime' => array(
'exclude' => 1,
'l10n_mode' => 'mergeIfNotBlank',
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.starttime',
'config' => array(
'type' => 'input',
'size' => 13,
'max' => 20,
'eval' => 'datetime',
'checkbox' => 0,
'default' => 0,
'range' => array(
'lower' => mktime(0, 0, 0, date('m'), date('d'), date('Y'))
),
),
),
'endtime' => array(
'exclude' => 1,
'l10n_mode' => 'mergeIfNotBlank',
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.endtime',
'config' => array(
'type' => 'input',
'size' => 13,
'max' => 20,
'eval' => 'datetime',
'checkbox' => 0,
'default' => 0,
'range' => array(
'lower' => mktime(0, 0, 0, date('m'), date('d'), date('Y'))
),
),
),
'title' => array(
'exclude' => 0,
'label' => 'LLL:EXT:moody_books/Resources/Private/Language/locallang_db.xlf:tx_moodybooks_domain_model_book.title',
'config' => array(
'type' => 'input',
'size' => 30,
'eval' => 'trim,required'
),
),
'description' => array(
'exclude' => 0,
'label' => 'LLL:EXT:moody_books/Resources/Private/Language/locallang_db.xlf:tx_moodybooks_domain_model_book.description',
'config' => array(
'type' => 'input',
'size' => 30,
'eval' => 'trim'
),
),
),
);
?>
Die Funktion makeCategorizable scheint also gar nicht aufgerufen zu werden, bzw. zumindest nicht das zu tun was sie eigentlich tun sollte. Hat jemand eine Idee woran das liegt bzw. was ich falsch mache, und wie ich die Kategorisierung auch für mein Model hinkriege? Das würde mir enorm helfen. Getestet habe ich das ganze auf TYPO3 Version 6.1.0.
Vielen Dank