[TYPO3-english] Hints for writing extensions for TYPPO3 4.5 to 6.1

Norbert Sendetzky n.sendetzky at metaways.de
Fri Feb 14 11:18:33 CET 2014


Hi all

Last week, we released the first version of the Arcavias webshop extension that was fully working with TYPO3 from 4.5 to 6.1 (for those who are interested, see http://forum.typo3.org/index.php/t/200655/). While testing and rewriting the extension to get it running with the different TYPO3 versions, we made some experiences I would like to share.


If you've started writing your extension using Extbase instead of the old pi-based API, you have used the new Tx_ classes that provided a new an clean encapsulation of the required functionality. They are great and the 6.x series also has a compatibility layer for translating the Tx_ classes to the latest namespaced ones. Unfortunately, some implementations changed a lot and no translation layer is available.

One of those things is the handling of flash messages in the Tx_ action controller resp. the new namespaced one. In the Tx_Extbase_MVC_Controller_ActionController, there's a property named flashMessageContainer available, that contains the object to which we can add our important messages, e.g. if a non-recoverable error occurs:

$this->flashMessageContainer->add( ... );

In TYPO3 6.x the implmentation of the flash message objects changed very much and is totally incompatible with the $this->flashMessageContainer object because method names and nested objects are not the same as in the Tx_ variant. Also, no compatibility layer is provided for that. But, there's one for the very old t3lib_ implementation! So instead of using the cool new object, we have to use the "ancient" one to get things running for 4.x and 6.x:

t3lib_FlashMessageQueue::addMessage( new t3lib_FlashMessage( '<message>', 'Error', t3lib_Flashmessage::ERROR );


The scheduler tasks are another source of problems because the interface of the additional field provider has changed in a way that isn't backwards compatible.

In TYPO3 4.x, additional fields provider only extends from tx_scheduler_Task and must implement these methods:
- public function getAdditionalFields( array &$taskInfo, $task, tx_scheduler_Module $parentObject )
- public function saveAdditionalFields( array $submittedData, tx_scheduler_Task $task )
- public function validateAdditionalFields( array &$submittedData, tx_scheduler_Module $parentObject ) 

Additional fields provider in 6.x must implement the \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface, which has the following method signatures:
- public function getAdditionalFields( array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject )
- public function saveAdditionalFields( array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task )
- public function validateAdditionalFields( array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject )

The differences are what is expected as the last parameter of the methods. The objects handed over are not compatible and have different methods there is also no translation layer available that could be used. Our solution was to create two different classes, one for 4.x and one for 6.x that provides the correct interface and an abstract class with the common code for both, that is called by getAdditionalFields(), saveAdditionalFields() and validateAdditionalFields(). To use the correct class for the TYPO3 version, we used some kind of feature detection in ext_localconf.php (checking for version sooner or later always fails!):

if( class_exists( '\TYPO3\CMS\Scheduler\Task\AbstractTask' ) ) {
    $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['Arcavias\Arcavias\Scheduler\Task\Typo6'] = ...
} else {
    $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['Tx_Arcavias_Scheduler_Task_Typo4'] = ...
}


The last thing you have to be aware of (and the docs also mention this somewhere) is that the names of the Tx_ classes in ext_autoload.php must be always in lower case. Sometimes it also works when using the camel-cased names but not for the scheduler part! To make things more confusing, this must not be the case for the namespaced classes, so it must be:

'tx_arcavias_scheduler_task_typo4' => $extensionPath . 'Classes/Scheduler/Task/Typo4.php',
'tx_arcavias_scheduler_provider_typo4' => $extensionPath . 'Classes/Scheduler/Provider/Typo4.php',
'Arcavias\Arcavias\Scheduler\Task\Typo6' => $extensionPath . 'Classes/Scheduler/Task/Typo6.php',
'Arcavias\Arcavias\Scheduler\Provider\Typo6' => $extensionPath . 'Classes/Scheduler/Provider/Typo6.php',

where $extensionPath = t3lib_extMgm::extPath( 'arcavias' );


I hope this can save you some time if you face the same problems like we did. If you have a better solution for one of those problems, I would love to read yours :-)


Norbert



More information about the TYPO3-english mailing list