Ich arbeite mich gerade in extbase ein, weil das die Grundlage für eine neue Extension werden soll. Im Großen und Ganzen habe ich einen Überblick, wie extbase funktioniert und eine Extension aufgebaut wird. Allerdings habe ich bei meinen Tests bisher immer ein Problem mit updateActions.
Das Problem ist folgendes: Beim Aufruf der updateAction enthält der Parameter nicht den neu eingegeben Wert. Im Tx_Extbase_MVC_Controller_ActionController kommt der Request richtig an, aber beim Mapping auf ein neues DomainObject wird der neue Wert nicht übernommen. D.h. wiederum der Parameter der updateAction-Methode enthält den alten und nicht den neuen Wert.
Ich habe keine Erklärung für dieses Verhalten und hoffe, dass mir hier jemand helfen kann. List, new, create, edit und delete funktionieren.
Noch etwas Quellcode:
Mein Model:
class Tx_SimpleExtbaseTest_Domain_Model_SingleObject extends Tx_Extbase_DomainObject_AbstractEntity {
/**
* name
*
* @var string
* @validate NotEmpty
*/
protected $name;
/**
* scope
*
* @var string
* @validate NotEmpty
*/
protected $scope;
[...]
/**
* A repository for singleObject
*/
class Tx_SimpleExtbaseTest_Domain_Repository_SingleObjectRepository extends Tx_Extbase_Persistence_Repository {
}
Controller:
class Tx_SimpleExtbaseTest_Controller_SingleObjectController extends Tx_Extbase_MVC_Controller_ActionController {
/**
* @var Tx_SimpleExtbaseTest_Domain_Repository_SingleObjectRepository
*/
protected $singleObjectRepository;
/**
* Initializes the current action
*/
public function initializeAction() {
$this->singleObjectRepository = t3lib_div::makeInstance('Tx_SimpleExtbaseTest_Domain_Repository_SingleObjectRepository');
}
/**
* action show
*
* @param $singleObject
* @return void
*/
public function showAction(Tx_SimpleExtbaseTest_Domain_Model_SingleObject $singleObject) {
$this->view->assign('singleObject', $singleObject);
}
/**
* action list
*
* @return void
*/
public function listAction() {
$singleObjects = $this->singleObjectRepository->findAll();
$this->view->assign('singleObjects', $singleObjects);
}
/**
* action new
*
* @param $newSingleObject
* @dontvalidate $newSingleObject
* @return void
*/
public function newAction(Tx_SimpleExtbaseTest_Domain_Model_SingleObject $newSingleObject = NULL) {
$this->view->assign('newSingleObject', $newSingleObject);
}
/**
* action create
*
* @param $newSingleObject
* @return void
*/
public function createAction(Tx_SimpleExtbaseTest_Domain_Model_SingleObject $newSingleObject) {
$this->singleObjectRepository->add($newSingleObject);
$this->flashMessageContainer->add('Your new SingleObject was created.');
$this->redirect('list');
}
/**
* action edit
*
* @param $singleObject
* @return void
*/
public function editAction(Tx_SimpleExtbaseTest_Domain_Model_SingleObject $singleObject) {
$this->view->assign('singleObject', $singleObject);
}
/**
* action update
*
* @param $singleObject
* @return void
*/
public function updateAction(Tx_SimpleExtbaseTest_Domain_Model_SingleObject $singleObject) {
$this->singleObjectRepository->update($singleObject);
$this->flashMessageContainer->add('Your SingleObject was updated.');
$this->redirect('list');
}
/**
* action delete
*
* @param $singleObject
* @return void
*/
public function deleteAction(Tx_SimpleExtbaseTest_Domain_Model_SingleObject $singleObject) {
$this->singleObjectRepository->remove($singleObject);
$this->flashMessageContainer->add('Your SingleObject was removed.');
$this->redirect('list');
}
}
ext_localconf.php:
if (!defined ('TYPO3_MODE')) die ('Access denied.');
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$_EXTKEY] = unserialize($_EXTCONF);
/**
* Configure the Plugin to call the
* right combination of Controller and Action according to
* the user input (default settings, FlexForm, URL etc.)
*/
Tx_Extbase_Utility_Extension::configurePlugin(
$_EXTKEY, // The extension name (in UpperCamelCase) or the extension key (in lower_underscore)
'Pi1', // A unique name of the plugin in UpperCamelCase
array ( // An array holding the controller-action-combinations that are accessible
'SingleObject' => 'list,show,new,create,delete,edit,update', // The first controller and its first action will be the default
),
array( // An array of non-cachable controller-action-combinations (they must already be enabled)
'SingleObject' => 'list,show,new,create,delete,edit,update',
)
);
ext_tables.php:
if (!defined('TYPO3_MODE')) {
die ('Access denied.');
}
Tx_Extbase_Utility_Extension::registerPlugin($_EXTKEY, 'Pi1', 'Simple Extbase Test');
t3lib_extMgm::addStaticFile($_EXTKEY, 'Configuration/TypoScript', 'simpleExtbaseTest');
t3lib_extMgm::addLLrefForTCAdescr('tx_simpleextbasetest_domain_model_singleobject', 'EXT:simple_extbase_test/Resources/Private/Language/locallang_csh_tx_simpleextbasetest_domain_model_singleobject.xml');
t3lib_extMgm::allowTableOnStandardPages('tx_simpleextbasetest_domain_model_singleobject');
$TCA['tx_simpleextbasetest_domain_model_singleobject'] = array(
'ctrl' => array(
'title' => 'LLL:EXT:simple_extbase_test/Resources/Private/Language/locallang_db.xml:tx_simpleextbasetest_domain_model_singleobject',
'label' => 'name',
'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',
),
'dynamicConfigFile' => t3lib_extMgm::extPath($_EXTKEY) . 'Configuration/TCA/SingleObject.php',
'iconfile' => t3lib_extMgm::extRelPath($_EXTKEY) . 'Resources/Public/Icons/tx_simpleextbasetest_domain_model_singleobject.gif'
),
);
TCA:
if (!defined ('TYPO3_MODE')) {
die ('Access denied.');
}
$TCA['tx_simpleextbasetest_domain_model_singleobject'] = array(
'ctrl' => $TCA['tx_simpleextbasetest_domain_model_singleobject']['ctrl'],
'interface' => array(
'showRecordFieldList' => 'sys_language_uid, l10n_parent, l10n_diffsource, hidden, name, scope',
),
'types' => array(
'1' => array('showitem' => 'sys_language_uid;;;;1-1-1, l10n_parent, l10n_diffsource, hidden;;1, name, scope,--div--;LLL:EXT:cms/locallang_ttc.xml:tabs.access,starttime, endtime'),
),
'palettes' => array(
'1' => array('showitem' => ''),
),
'columns' => array(
'sys_language_uid' => array(
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_general.xml: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.xml:LGL.allLanguages', -1),
array('LLL:EXT:lang/locallang_general.xml:LGL.default_value', 0)
),
),
),
'l10n_parent' => array(
'displayCond' => 'FIELD:sys_language_uid:>:0',
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_general.xml:LGL.l18n_parent',
'config' => array(
'type' => 'select',
'items' => array(
array('', 0),
),
'foreign_table' => 'tx_simpleextbasetest_domain_model_singleobject',
'foreign_table_where' => 'AND tx_simpleextbasetest_domain_model_singleobject.pid=###CURRENT_PID### AND tx_simpleextbasetest_domain_model_singleobject.sys_language_uid IN (-1,0)',
),
),
'l10n_diffsource' => array(
'config' => array(
'type' => 'passthrough',
),
),
't3ver_label' => array(
'label' => 'LLL:EXT:lang/locallang_general.xml:LGL.versionLabel',
'config' => array(
'type' => 'input',
'size' => 30,
'max' => 255,
)
),
'hidden' => array(
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_general.xml:LGL.hidden',
'config' => array(
'type' => 'check',
),
),
'starttime' => array(
'exclude' => 1,
'l10n_mode' => 'mergeIfNotBlank',
'label' => 'LLL:EXT:lang/locallang_general.xml: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.xml: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'))
),
),
),
'name' => array(
'exclude' => 0,
'label' => 'LLL:EXT:simple_extbase_test/Resources/Private/Language/locallang_db.xml:tx_simpleextbasetest_domain_model_singleobject.name',
'config' => array(
'type' => 'input',
'size' => 30,
'eval' => 'trim,required'
),
),
'scope' => array(
'exclude' => 0,
'label' => 'LLL:EXT:simple_extbase_test/Resources/Private/Language/locallang_db.xml:tx_simpleextbasetest_domain_model_singleobject.scope',
'config' => array(
'type' => 'input',
'size' => 30,
'eval' => 'trim,required'
),
),
),
);
Und zu guter Letzt das edit-Template:
<div class="csc-header csc-header-n1"><h1 class="csc-firstHeader">{f:translate(key:'edit')}</h1></div>
<p class="bodytext">{f:translate(key:'singleobject')}</p>
<f:form method="post" controller="SingleObject" action="update" name="updatedSingleObject" object="{singleObject}" arguments="{singleObject: singleObject}" >
<p>
<label for="name"><f:translate key="singleobject.name"></f:translate></label>
<f:form.textbox property="name" />
</p>
<p>
<label for="scope"><f:translate key="singleobject.scope"></f:translate></label>
<f:form.textbox property="scope" />
</p>
<f:form.submit value="{f:translate(key:'singleobject.form.save')}" />
</f:form>
Was habe ich in den Tutorials übersehen?