"Erweitere ich das "original" Model per Hand um obenstehende Code, klappt es problemlos."
Wo ist dann das Problem?
Ich will das Model der zu erweiternden Extension nicht "manuel" abändern, sondern nur mit einer zweiten Extension erweitern (Updatesicherheit).
Habe es nun endlich hin bekommen. Ich glaube ein fehlender Backslash am Anfang der zu erweiternden Klasse im neuen Model hat mich schier in den Wahnsinn getrieben. Desweiteren scheint mir die vom Extension Builder 2.5.2 generierte ext_tables.php nicht brauchbar. Diejenige von v2.5.1 jedoch schon. Bei der setup.txt verhält es sich genau anders rum...
Ich habe nun noch einmal zwei Extensions erstellt und teile hier die nötigen Files von Extension2, welche Extension1 um ein Feld erweitert. Typo3 läuft momentan in Version 6.0.4.
Die Files von Extension1 sind wohl uninteressant. Die Extension heisst "Extension1" hat den VendorName "Vendor", den Extension-Key "ext1" und ein Model "Model1" mit einem Feld "field1".
Nun zur relevanten Extension2:
Name: Extension2
VendorName: Vendor
Key: ext2
Model: Model2 (erweitert Model1)
Feld: field2
Hier die relevanten Files:
Classes/Domain/Model/Model2.php:
<?php
namespace Vendor\Ext2\Domain\Model;
/***************************************************************
* Copyright notice
*
* (c) 2013
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
*
*
* @package ext2
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*
*/
class Model2 extends \Vendor\Ext1\Domain\Model\Model1 {
/**
* field2
*
* @var \string
*/
protected $field2;
/**
* Returns the field2
*
* @return \string $field2
*/
public function getField2() {
return $this->field2;
}
/**
* Sets the field2
*
* @param \string $field2
* @return void
*/
public function setField2($field2) {
$this->field2 = $field2;
}
}
?>
Configuration/TypoScript/setup.txt
config.tx_extbase{
persistence{
classes{
Vendor\Ext1\Domain\Model\Model1 {
subclasses {
Tx_Ext2_Model2 = Vendor\Ext2\Domain\Model\Model2
}
}
Vendor\Ext2\Domain\Model\Model2 {
mapping {
tableName = tx_ext1_domain_model_model1
recordType = Tx_Ext2_Model2
}
}
}
}
}
ext_tables.php
<?php
if (!defined('TYPO3_MODE')) {
die ('Access denied.');
}
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'Configuration/TypoScript', 'Extension2');
\TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA('tx_ext1_domain_model_model1');
if (!isset($TCA['tx_ext1_domain_model_model1']['ctrl']['type'])) {
// no type field defined, so we define it here. This will only happen the first time the extension is installed!!
$TCA['tx_ext1_domain_model_model1']['ctrl']['type'] = 'tx_extbase_type';
$tempColumns = array();
$tempColumns[$TCA['tx_ext1_domain_model_model1']['ctrl']['type']] = array(
'exclude' => 1,
'label' => 'LLL:EXT:ext2/Resources/Private/Language/locallang_db.xlf:tx_ext2_domain_model_model2.tx_extbase_type',
'config' => array(
'type' => 'select',
'items' => array(
array('LLL:EXT:ext2/Resources/Private/Language/locallang_db.xlf:tx_ext2_domain_model_model2.tx_extbase_type.0','0'),
),
'size' => 1,
'maxitems' => 1,
'default' => 'Tx_Ext2_Model2'
)
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tx_ext1_domain_model_model1', $tempColumns, 1);
}
$TCA['tx_ext1_domain_model_model1']['types']['Tx_Ext2_Model2']['showitem'] = $TCA['tx_ext1_domain_model_model1']['types']['1']['showitem'];
$TCA['tx_ext1_domain_model_model1']['columns'][$TCA['tx_ext1_domain_model_model1']['ctrl']['type']]['config']['items'][] = array('LLL:EXT:ext2/Resources/Private/Language/locallang_db.xlf:tx_ext2_domain_model_model2','Tx_Ext2_Model2');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('tx_ext1_domain_model_model1', $TCA['tx_ext1_domain_model_model1']['ctrl']['type'],'','after:hidden');
$tmp_ext2_columns = array(
'field2' => array(
'exclude' => 0,
'label' => 'LLL:EXT:ext2/Resources/Private/Language/locallang_db.xlf:tx_ext2_domain_model_model2.field2',
'config' => array(
'type' => 'input',
'size' => 30,
'eval' => 'trim'
),
),
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tx_ext1_domain_model_model1',$tmp_ext2_columns);
$TCA['tx_ext1_domain_model_model1']['columns'][$TCA['tx_ext1_domain_model_model1']['ctrl']['type']]['config']['items'][] = array('LLL:EXT:ext2/Resources/Private/Language/locallang_db.xlf:tx_ext1_domain_model_model1.tx_extbase_type.Tx_Ext2_Model2','Tx_Ext2_Model2');
$TCA['tx_ext1_domain_model_model1']['types']['Tx_Ext2_Model2']['showitem'] = $TCA['tx_ext1_domain_model_model1']['types']['1']['showitem'];
$TCA['tx_ext1_domain_model_model1']['types']['Tx_Ext2_Model2']['showitem'] .= ',--div--;LLL:EXT:ext2/Resources/Private/Language/locallang_db.xlf:tx_ext2_domain_model_model2,';
$TCA['tx_ext1_domain_model_model1']['types']['Tx_Ext2_Model2']['showitem'] .= 'field2';
?>
ext_tables.sql
#
# Table structure for table 'tx_ext1_domain_model_model1'
#
CREATE TABLE tx_ext1_domain_model_model1 (
field2 varchar(255) DEFAULT '' NOT NULL,
tx_extbase_type varchar(255) DEFAULT '' NOT NULL,
);
Ich hab dann einfach die Templates von Extension1 in das Verzeichnis von Extension2 kopiert, um die gewünschten Felder erweitert und in Configuration/TypoScript/constants.txt die Template-Pfade für das Plugin von Extension1 angepasst. Funktioniert nun soweit einwandfrei, ist jedoch noch nicht bis ins Detail getestet. Wüsste jedoch nicht, was noch schief gehen sollte 😉
Ich hoffe, dass dies dem Ein oder Anderen die Zeit erspart, welche ich dafür gebraucht habe.
Grüsse
Kjuuze