TYPO3 - Hooks in Extbase Extensions
Aus Wikizone
Version vom 18. Juni 2015, 11:40 Uhr von 37.49.33.84 (Diskussion) (Die Seite wurde neu angelegt: „== Hooks in Extbase Extensions == Hinweis: eine Alternative für Extbase Extensions sind die Signal Slots. '''Beispiel:''' Hook be…“)
Hooks in Extbase Extensions
Hinweis: eine Alternative für Extbase Extensions sind die Signal Slots.
Beispiel: Hook beim Löschen eines Datensatzes im Backend
List view uses TCEmain hooks during its operations, so you can use one of them to intersect delete action, i.e.: processCmdmap_deleteAction
1. Register your hooks class in typo3conf/ext/your_ext/ext_tables.php
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass'][] = 'VENDORNAME\\YourExt\\Hooks\\ProcessCmdmap';
Create a class with valid namespace and path (according to previous step) file: typo3conf/ext/your_ext/Classes/Hooks/ProcessCmdmap.php
<?php
namespace VENDORNAME\YourExt\Hooks;
class ProcessCmdmap {
/**
* hook that is called when an element shall get deleted
*
* @param string $table the table of the record
* @param integer $id the ID of the record
* @param array $record The accordant database record
* @param boolean $recordWasDeleted can be set so that other hooks or
* @param DataHandler $tcemainObj reference to the main tcemain object
* @return void
*/
function processCmdmap_postProcess($command, $table, $id, $value, $dataHandler) {
if ($command == 'delete' && $table == 'tx_yourext_domain_model_something') {
// Perform something before real delete
// You don't need to delete the record here it will be deleted by CMD after the hook
}
}
}
Don't forget to clear system cache after registering new hook's class
Verfügbare Hooks: http://typo3.org/api/typo3cms/namespace_t_y_p_o3_1_1_c_m_s_1_1_version_1_1_hook.html