Extbase Extensions - Snippets und Glossar
Beinhaltet z.T. auch Fluid
Hinweis neue Namespace Regelung für Klassen
Extbase Änderungen ab TYPO3 V6
Glossar
Snippets Links
http://typo3.org/documentation/snippets/
Mehrere Models in einem Formular / einer Action steuern
Rendering des Views steuern
Timestamp - crdate und tstamp nutzen
Rendering verhindern
Am Ende der Action wird implizit immer
return $this->view->render();
ausgeführt (auch wenn man es nicht schreibt). Will man das verhindern muß man
return false;
zurückgeben
Objekt-Datenbank-Abfragen steuern
Das Ergebnis der findAll() Funktion im Controller läßt sich mit dem QueryInterface steuern. Z.B. kann man im Repository die Standardsortierung festlegen.
Extbase - Sortierung und Abfrage von Objekten
TypoScript Konfiguration im Controller nutzen
Hinweis zu Settings in TypoScript
Im Action Controller und im Fluid Template sind nur die Objekte über $this->settings bzw. settings.objektname sichtbar die in plugin.tx_extname.settings liegen.
TypoScript
plugin.tx_some-extname.settings {
myXsetting = XXXX
}
PHP
$valX = $this->settings['myXsetting'];
E-Mails mit Extbase
http://www.benny-vs-web.de/typo3/extbase-fluid-zum-rendern-von-e-mail-templates-verwenden/
Lokalisierung - Language Files
Im Extbase Controller lokalisieren
Z.B. bei Fehlermeldungen. flashMessages oder speziellen Ausgaben
Tx_Extbase_Utility_Localization::translate($langkey,$extensionName)
$extensionName = Extbase name (UpperCammelCase ohen Unterstriche)
$langkey muss der locallang.xml datei bzw. xlf hinzugefügen.
<label index="tx_t3easyplugins_domain_model_plugin.createdSuccessful">Your new Plugin was created.</label>
Unten ein kleines Beispiel. Tx_Extbase_Utility_Localization::translate
/**
* action create
*
* @param $newEntry
* @return void
*/
public function createAction(Tx_T3easyPlugins_Domain_Model_Plugin $newEntry) {
$this->entryRepository->add($newEntry);
$this->flashMessageContainer->add(Tx_Extbase_Utility_Localization::translate('tx_t3easyplugins_domain_model_Plugin.createdSuccessful', 'T3easyPlugins'));
$this->redirect('list');
}
locallang.xml
... <label index="tx_t3easyplugins_domain_model_plugin.createdSuccessful">Your new Plugin was created.</label> ...
Actions
Controller und Actions Basics
Neue Action realisieren
- Action registrieren (localconf.php)
- Methode für die Action schreiben (im Controller des Objektes)
- Auf gewünschten View weiterleiten (z.B. $this->redirect('list'); )
Auf Daten von anderen Models / Repositorys im Controller zugreifen. Dependency Injection
Will man auf Daten anderer Extensions zugreifen oder verknüpfte Daten komplett ohne ein Objekt des Aggregate Root (also die Haupttabelle) ausgeben muß man die Datenstruktur Injecten. Grundsätzlich kann man mit der Inject Methode aus jeder Extension heraus auf Daten anderer Extensions zugreifen.
Beispiel: Im Controller steht wegen der strikten Trennung der Modelle erstmal das Repository (Die Datenstruktur) des Models zur Verfügung. Die verknüpften Daten (hier im Beispiels die Genres, gibt der View zwar über die Verknüpfung aus, das sind aber nur die mit dem jeweiligen Datensatz verknüpften Daten. Z.B. die Genres einer Band. Will man z.B. alle Genres im Listview der Bands ausgeben braucht man ein Repository der Genres und muß den Genre Controller in den Band Controller injecten. Dann kann man auf alle Funktionen des Genre Controllers auch aus dem Band Controller zugreifen. So bleibt auch alles sauber getrennt.
- eigenes Repository für verknüpfte Daten erstellen (z.B. Genre)
/**
* genreRepository
*
* @var \Geobit\Gbbandpass\Domain\Repository\GenreRepository
* @inject
*/
protected $genreRepository = NULL;
- Im Controller (Hauptcontroller) deiner Extension injectest du das gewünschte Repository. Allerdings gibt es unterschiedliche Methoden je nachdem welche Typo3 Version du verwendest.
Dependency Injection 'TYPO3 ab 6.0
/**
* @var \Vendor\Extension\Domain\Repository\SomeRepository
* @inject
*/
protected $someRepository;
Dependency Injection TYPO3 = 4.7
/**
* @var Tx_MyExtension_Domain_Repository_SomeRepository
* @inject
*/
protected $someRepository;
Dependency Injection TYPO3 vor 4.7
/**
* @var Tx_MyExtension_Domain_Repository_SomeRepository
*/
protected $someRepository;
/**
* Inject SomeRepository
* @param Tx_MyExtension_Domain_Repository_SomeRepository $someRepository
* @return void
*/
public function injectSomeRepository(Tx_MyExtension_Domain_Repository_SomeRepository $someRepository) {
$this->someRepository = $someRepository;
}
Jetzt kann man $this->someRepository mit all seinen Methoden auch in diesem Controller nutzen.
Hinweis: Nach Änderung System Cache löschen !
Controller-Action Kombinationen für Frontend-Plugins definieren
http://docs.typo3.org/typo3cms/ExtbaseFluidBook/b-ExtbaseReference/Index.html
In ext_localconf.php sind erlaubte Actions hinterlegt. Der erste Eintrag ist die Default-Action.
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin( 'Geobit.' . $_EXTKEY, 'Mailformtest', array( 'Mailform' => 'list, show, new, create', ), // non-cacheable actions array( 'Mailform' => 'create, ', ) );
Zu diesem Beispiel gehört der Controller unter
Classes/Controller/MailformController.php
Domainmodel Beispiele
M:N Verbindung komplett
Diverse
Actions anlegen
Im Controller:
/**
* action list
*
* @return void
*/
public function listAction() {
$myextname = $this->myextRepository->findAll();
$this->view->assign('myextname', $myextname);
}
addFlashMessage
Im Controller
$this->addFlashMessage('This is a simple success message');
$this->addFlashMessage('The message body', 'Message title', \TYPO3\CMS\Core\Messaging\AbstractMessage::OK, TRUE);
$this->addFlashMessage('<strong>HTML-Messageplement</strong>', '', \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR);
Existierende Extbase Klassen erweitern
( Früher XCLASS ) - http://blog.sebastiaandejonge.com/articles/2013/june/11/class-extension-in-extbase/
Default Sortierung in Extbase
Beispiel aus Slidercalc
/**
* The repository for Sliders
*/
class SliderRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
protected $defaultOrderings = array(
'category.sorting' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
'sorting' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING
//'date' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
);
}
Quelle: http://t3n.de/magazin/zehn-tipps-tricks-extbase-fluid-227639/2/ (11/2014)
Default-Sortierung im Repository
Nicht unbedingt unbekannt, aber weitestgehend ungenutzt ist ein Feature, welches in Extbase 1.3 hinzugekommen ist: Im Repository besteht die Möglichkeit, das Ergebnis nach bestimmten Feldern aufsteigend oder absteigend zu sortieren. Dies wird beispielsweise mittels „
$query->setOrderings(array('name' => Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING));
erledigt.
Um dies nicht für jede einzelne Repository-Funktion einstellen zu müssen, gibt es die Eigenschaft defaultOrderings:
Im Repository
protected $defaultOrderings = array ('name' => Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING);
Debugging
Fehlermeldung class_parents(): object or string expected
Nachdem man neue Properties hinzugefügt hat kommt obige Fehlermeldung. Dies ist ein Bug in Extbase. Nur Truncating cf_extbase_reflection works. (Bei 4.5 die Extbase Cachetabellen leeren)
Debugging im Controller
Beispiel
print \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump( $this );
Beispiel
t3lib_utility_Debug::debug($var, 'Debug: ' . __FILE__ . ' in Line: ' . __LINE__); # namespaces \TYPO3\CMS\Core\Utility\DebugUtility::debug($var, 'Debug: ' . __FILE__ . ' in Line: ' . __LINE__);
Beispiel
Tx_Extbase_Utility_Debugger::var_dump($var); # namespaces \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($var);
Debugging wenn keine Datensätze gefunden werden
Im Repository kann man das Queryinterface überschreiben und so z.B. die Abfrage der storage Page unterbinden (alle werden ausgegeben). Auch Fehler im sql werden sichtbar.
/**
* @return QueryInterface
*/
public function createQuery(){
$query = parent::createQuery();
$query->getQuerySettings()->setRespectStoragePage(FALSE);
return $query;
}
Zugriff auf TypoScript
getConfiguration ( $configurationType, $extensionName = NULL, $pluginName = NULL )
Daten aus anderen Extensions
Zugriff auf fe_user
Extbase - Zugriff auf die fe_user Tabelle
Zugriff auf andere Extensions
Extbase - Zugriff auf Tabellen anderer Extbase Extensions
AJAX mit Extbase
AJAX über neuen Page Type
Quelle: http://t3-developer.com/extbase-fluid/extensions-erweitern/ajax-in-extensions/ajaxcalls-mit-pagetype/ (2014/12)
Die Verwendung eines eigenen page Types für Ajax Calls ist relativ simpel. Zunächst müsst ihr euer Extensionsetup um einen neuen PageType erweitern. Die PageType Nummer muss einmalig in der Installation sein, also ggf. bereits vergebene PageTypes für RSS, Sitemaps, Print & Co beachten.
Extensionsetup
Bitte beachtet das ihr in der letzten Zeile eure den Extensionnamen ohne 'tx_' Prefix angeben müsst!
TypoScript
ajaxCall = PAGE
ajaxCall {
typeNum = 999
config.disableAllHeaderCode = 1
config.metaCharset = UTF-8
10 = COA
10 < tt_content.list.20.myextension_myplugin
}
Der AjaxCall in jQuery
$('#jq-send').click(function(e) {
$.ajax({
var controller = tx_myExt_myplugin[controller]= blabla;
var action = tx_myExt_myplugin[action]= meineControllerFunction; // ohne Action am Ende
var pagetype = 999;
var path = $(location).attr('href');
url: path + '/?' + controller + '&' + action + '&type=' + pagetype
//optionale Parameter
data: 'useruid=' + useruid,
success: function(result) {
console.log(result);
//hier kommen eure Anweisungen rein
},
error: function(error) {
console.log(error);
}
});
});
Ein Beispiel findet ihr auch in meiner Blogextension "multiblog" auf Github: ajaxCall in Blogextension
Ajax Function im Controller
Die Controllerfunction muss natürlich wie jede Action in der ext_localconf.php registriert sein. Innerhalb dieser Action steht euch die ganz normale Extbase Umgebung zur Verfügung, also alles das was ihr in 'normalen' Funktionen auch habt (injected Repositories, mapped Tables, settings etc.) Genau das ist der Unterschied zu einem AjaxCall über eID, das komplette TSFE ist geladen.
Am Ende der Funktion müsst Ihr euch nur entscheiden, was Ihr zurückgeben wollt:
Rückgabe eine json strings (z.B. Ergebnisarray):
return json_encode($myArray);
Rückgabe eines kompletten Views als html string. Am Ende der Ajax Funktion im Controller setzt Ihr ganz normal euren View (Template muss vorhanden sein):
$this->view->assign('myAjaxAction, $values);
Keinerlei Rückgabe z.B wenn Ihr nur Daten nur für einen Counter speichert:
exit;
Innerhalb von der jQuery Funktion success:function(result) { } wird dann das Ergebnis ausgewertet. Die vom Controller zurückgegebenen Werte stehen in der Variablen result zur Verfügung.
AJAX Call über eid Mechanismus
Quelle: http://t3-developer.com/extbase-fluid/extensions-erweitern/ajax-in-extensions/ajax-dispatcher-eid-in-typo3-61/ (2014/12)
Ajax Dispatcher für TYPO3 6.2 - wichtige Hinweise!
Damit das nachfolgende Script auch unter TYPO3 6.2.3 funktioniert, müssen folgende Zeilen geändert werden:
Zeile 101:
\TYPO3\CMS\Core\Core\Bootstrap::getInstance();
Siehe auch forge.typo3.org/issues/59070.
Ajax Dispaytcher für TYPO3 6.1 und Namespaces. Die Datei ist getestet und läuft auch ;). Ihr müsst in Zeile 82 + 83 den von Euch benutzen Vendor und Extension Namen einsetzten.
Siehe auch alle weiteren Angaben im Kommentarbereich des Dispatchers.
<?php
/** *************************************************************
*
* Extbase Dispatcher for Ajax Calls TYPO3 6.1 namespaces
*
* IMPORTANT Use this script only in Extensions with namespaces
*
* Klaus Heuer <klaus.heuer@t3-developer.com>
*
* 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 2 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!
* ************************************************************* */
/** ************************************************************
* Usage of this script:
*
* - Copy this script in your Extension Dir in the Folder Classes
* - Set the Vendor and Extension Name in Line 82 + 83
* - Include the next line in the ext_localconf.php, change the ext name!
* - $TYPO3_CONF_VARS['FE']['eID_include']['ajaxDispatcher'] = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('myExtension').'Classes/EidDispatcher.php';
*
* Use for Ajax Calls in your jQuery Code:
*
* $('.jqAjax').click(function(e) {
* var uid = $(this).find('.uid').html();
* var storagePid = '11';
*
* $.ajax({
* async: 'true',
* url: 'index.php',
* type: 'POST',
*
* data: {
* eID: "ajaxDispatcher",
* request: {
* pluginName: 'patsystem',
* controller: 'Todo',
* action: 'findTodoByAjax',
* arguments: {
* 'uid': uid,
* 'storagePid': storagePid
* }
* }
* },
* dataType: "json",
*
* success: function(result) {
* console.log(result);
* },
* error: function(error) {
* console.log(error);
* }
* });
*************************************************************** */
/**
* Gets the Ajax Call Parameters
*/
$ajax = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('request');
/**
* Set Vendor and Extension Name
*
* Vendor Name like your Vendor Name in namespaces
* ExtensionName in upperCamelCase
*/
$ajax['vendor'] = 'T3Developer';
$ajax['extensionName'] = 'ProjectsAndTasks';
/**
* @var $TSFE \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
*/
$TSFE = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController', $TYPO3_CONF_VARS, 0, 0);
\TYPO3\CMS\Frontend\Utility\EidUtility::initLanguage();
// Get FE User Information
$TSFE->initFEuser();
// Important: no Cache for Ajax stuff
$TSFE->set_no_cache();
//$TSFE->checkAlternativCoreMethods();
$TSFE->checkAlternativeIdMethods();
$TSFE->determineId();
$TSFE->initTemplate();
$TSFE->getConfigArray();
\TYPO3\CMS\Core\Core\Bootstrap::getInstance()->loadConfigurationAndInitialize();
$TSFE->cObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer');
$TSFE->settingLanguage();
$TSFE->settingLocale();
/**
* Initialize Database
*/
\TYPO3\CMS\Frontend\Utility\EidUtility::connectDB();
/**
* @var $objectManager \TYPO3\CMS\Extbase\Object\ObjectManager
*/
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
/**
* Initialize Extbase bootstap
*/
$bootstrapConf['extensionName'] = $ajax['extensionName'];
$bootstrapConf['pluginName'] = $ajax['pluginName'];
$bootstrap = new TYPO3\CMS\Extbase\Core\Bootstrap();
$bootstrap->initialize($bootstrapConf);
$bootstrap->cObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tslib_cObj');
/**
* Build the request
*/
$request = $objectManager->get('TYPO3\CMS\Extbase\Mvc\Request');
$request->setControllerVendorName($ajax['vendor']);
$request->setcontrollerExtensionName($ajax['extensionName']);
$request->setPluginName($ajax['pluginName']);
$request->setControllerName($ajax['controller']);
$request->setControllerActionName($ajax['action']);
$request->setArguments($ajax['arguments']);
$response = $objectManager->create('TYPO3\CMS\Extbase\Mvc\ResponseInterface');
$dispatcher = $objectManager->get('TYPO3\CMS\Extbase\Mvc\Dispatcher');
$dispatcher->dispatch($request, $response);
echo $response->getContent();
//die();
?>
Mehrere Modelle in einem View
Übergabe mehrerer Objekte aus einem View
In Fluid
<f:link.action action="newMetadevice" arguments="{rma : rma, device : device}">add</f:link.action>
Im Controller 1. Direkt im Header
public function createDeviceAction(\Geobit\Gbrma\Domain\Model\Rma $rma,\Geobit\Gbrma\Domain\Model\Device $device){...}
2. Im Controller mit getArgument()
$deviceClassUid = intval($this->request->getArgument('deviceClassUid'));
Daten mit mehreren nicht persistenten Daten in Sessions
http://stackoverflow.com/questions/27821750/multiple-objects-in-one-fluid-form (2015-03)
In order to pass non persistent objects between multiple actions, I would suggest that you store the objects serialized in a TYPO3 session variable. Doing so, you can restore the objects in the target action.
Below you find a working example which can also be found here. https://github.com/derhansen/extbase_validation_new_pm/blob/master/Classes/Controller/MultipleStepsController.php
<?php
namespace derhansen\ValidationExamplesNew\Controller;
/***************************************************************
* Copyright notice
*
* (c) 2013 Torben Hansen <derhansen@gmail.com>
*
* 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!
***************************************************************/
/**
* Multiple Steps Controller
*
* @package validation_examples_new
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*
*/
class MultipleStepsController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
/**
* addressdataRepository
*
* @var \derhansen\ValidationExamplesNew\Domain\Repository\AddressdataRepository
* @inject
*/
protected $addressdataRepository;
/**
* API Service
*
* @var \derhansen\ValidationExamplesNew\Service\ExternalApiService
* @inject
*/
protected $apiService;
/**
* Step1
*
* @param \derhansen\ValidationExamplesNew\Domain\Model\Step1Data $step1data
* @dontvalidate $step1data
*/
public function step1Action(\derhansen\ValidationExamplesNew\Domain\Model\Step1Data $step1data = NULL) {
/* Check if step1data is available in session */
if ($GLOBALS['TSFE']->fe_user->getKey('ses', 'step1data') && $step1data == NULL) {
$step1data = unserialize($GLOBALS['TSFE']->fe_user->getKey('ses', 'step1data'));
}
$this->view->assign('step1data', $step1data);
}
/**
* Step1 redirect action
*
* @param \derhansen\ValidationExamplesNew\Domain\Model\Step1Data $step1data
*/
public function step1redirectAction(\derhansen\ValidationExamplesNew\Domain\Model\Step1Data $step1data) {
$GLOBALS['TSFE']->fe_user->setKey('ses', 'step1data', serialize($step1data));
$GLOBALS['TSFE']->fe_user->storeSessionData();
$this->redirect('step2');
}
/**
* Step2
*
* @param \derhansen\ValidationExamplesNew\Domain\Model\Step2Data $step2data
* @dontvalidate $step2data
*/
public function step2Action(\derhansen\ValidationExamplesNew\Domain\Model\Step2Data $step2data = NULL) {
/* Check if step2data is available in session */
if ($GLOBALS['TSFE']->fe_user->getKey('ses', 'step2data') && $step2data == NULL) {
$step2data = unserialize($GLOBALS['TSFE']->fe_user->getKey('ses', 'step2data'));
}
/* Set external validations errors if available */
$this->setApiValidationErrors('step2');
$this->view->assign('step2data', $step2data);
}
/**
* Step2 redirect action
*
* @param \derhansen\ValidationExamplesNew\Domain\Model\Step2Data $step2data
*/
public function step2redirectAction(\derhansen\ValidationExamplesNew\Domain\Model\Step2Data $step2data) {
$GLOBALS['TSFE']->fe_user->setKey('ses', 'step2data', serialize($step2data));
$GLOBALS['TSFE']->fe_user->storeSessionData();
$this->redirect('step3');
}
/**
* Step3
*
* @param \derhansen\ValidationExamplesNew\Domain\Model\Step3Data $step3data
* @dontvalidate $step3data
*/
public function step3Action(\derhansen\ValidationExamplesNew\Domain\Model\Step3Data $step3data = NULL) {
/* Check if step3data is available in session */
if ($GLOBALS['TSFE']->fe_user->getKey('ses', 'step3data') && $step3data == NULL) {
$step3data = unserialize($GLOBALS['TSFE']->fe_user->getKey('ses', 'step3data'));
}
/* Set external validations errors if available */
$this->setApiValidationErrors('step3');
$this->view->assign('step3data', $step3data);
}
/**
* Step3 redirect action
*
* @param \derhansen\ValidationExamplesNew\Domain\Model\Step3Data $step3data
*/
public function step3redirectAction(\derhansen\ValidationExamplesNew\Domain\Model\Step3Data $step3data) {
$GLOBALS['TSFE']->fe_user->setKey('ses', 'step3data', serialize($step3data));
$GLOBALS['TSFE']->fe_user->storeSessionData();
$this->redirect('create');
}
/**
* Create Action
*
* @return void
*/
public function createAction() {
$addressdata = $this->getAddressdataFromSession();
/* get validation results from API */
$apiresults = $this->apiService->validateMultipleSteps($addressdata);
if (count($apiresults) > 0) {
/* Save results to a session variable */
$GLOBALS['TSFE']->fe_user->setKey('ses', 'apiresults', $apiresults);
$GLOBALS['TSFE']->fe_user->storeSessionData();
/* Redirect to step with validation errors */
if (array_key_exists('step2', $apiresults)) {
$this->redirect('step2');
}
if (array_key_exists('step3', $apiresults)) {
$this->redirect('step3');
}
}
$this->addressdataRepository->add($addressdata);
$this->cleanUpSessionData();
$this->view->assign('message', 'Addressdata has been created');
}
/**
* Collects the addressdata from the multiple steps form stored in session variables
* and returns an addressdata object.
*
* @return \derhansen\ValidationExamplesNew\Domain\Model\Addressdata
*/
protected function getAddressdataFromSession() {
/** @var \derhansen\ValidationExamplesNew\Domain\Model\Step1Data $step1data */
$step1data = unserialize($GLOBALS['TSFE']->fe_user->getKey('ses', 'step1data'));
/** @var \derhansen\ValidationExamplesNew\Domain\Model\Step2Data $step2data */
$step2data = unserialize($GLOBALS['TSFE']->fe_user->getKey('ses', 'step2data'));
/** @var \derhansen\ValidationExamplesNew\Domain\Model\Step3Data $step3data */
$step3data = unserialize($GLOBALS['TSFE']->fe_user->getKey('ses', 'step3data'));
/** @var \derhansen\ValidationExamplesNew\Domain\Model\Addressdata $addressData */
$addressData = $this->objectManager->get('derhansen\ValidationExamplesNew\Domain\Model\Addressdata');
$addressData->setFirstname($step1data->getFirstname());
$addressData->setLastname($step1data->getLastname());
$addressData->setStreet($step2data->getStreet());
$addressData->setStreetnr($step2data->getStreetnr());
$addressData->setZip($step3data->getZip());
$addressData->setCity($step3data->getCity());
return $addressData;
}
/**
* Removes all session variables from the multiple steps form
*
* @return void
*/
protected function cleanUpSessionData() {
$GLOBALS['TSFE']->fe_user->setKey('ses', 'step1data', '');
$GLOBALS['TSFE']->fe_user->setKey('ses', 'step2data', '');
$GLOBALS['TSFE']->fe_user->setKey('ses', 'step3data', '');
$GLOBALS['TSFE']->fe_user->setKey('ses', 'apiresults', '');
$GLOBALS['TSFE']->fe_user->storeSessionData();
}
/**
* Sets validation errors for fields in the given step
*
* @param string $step The step
* @return void
*/
protected function setApiValidationErrors($step) {
$apiresults = $GLOBALS['TSFE']->fe_user->getKey('ses', 'apiresults');
if (array_key_exists($step, $apiresults)) {
/* Set Form Errors manually - get results from property mapper and add new errors */
$result = $this->getControllerContext()->getRequest()->getOriginalRequestMappingResults();
/* Add validation errors */
foreach ($apiresults[$step] as $key => $value) {
$error = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Validation\Error',
$apiresults[$step][$key], time());
$result->forProperty($step . 'data.' . $key)->addError($error);
}
$this->getControllerContext()->getRequest()->setOriginalRequestMappingResults($result);
}
}
}
?>