[TYPO3] SOLVED: t3lib_TCEmain hook processCmdmap_postProcess

Sander van Gelderen reply at to.list
Fri Jun 8 16:58:15 CEST 2007


Hi All,

I guess this was a tough one, it has cost me until now to find out the 
solution. Credit goes to Peter Bartels.

I share it here so others might profit:

I was using the wrong hook! In stead of using processCmdmap_postProcess 
I should have been using processDatamap_afterDatabaseOperations.

For completeness, here is my code:


<?php
/**
  * Class being included by TCEmain using a hook
  *
  * @author	Sander van Gelderen <mail at sandervangelderen.nl>
  */
class tx_svgfoobar_tcemain {
	
	var $debug = TRUE;

	/**
	 * This method is called by a hook in the TYPO3 Core Engine (TCEmain).
	 *
	 * @param	string		$command: The TCEmain operation status, fx. 'update'
	 * @param	string		$table: The table TCEmain is currently processing
	 * @param	string		$id: The records id (if any)
	 * @param	array			$value: The field names and their values to be processed
	 * @param	object		$reference: Reference to the parent object (TCEmain)
	 * @return	void
	 * @access	public
	 */
	
    function processDatamap_afterDatabaseOperations ($status, $table, 
$id, $fieldArray, &$reference) {
		if ($this->debug) t3lib_div::devLog 
('processDatamap_afterDatabaseOperations', 'svgfoobar', 0, 
array($status, $table, $id, $fieldArray, &$reference));
		if ($status == 'update' && $table == 'tx_svgfoobar_request') {
			
			//print_r("id = $id");
			//var_dump($reference);
			//die();
			
			
			//TODO get folder pids from TS
			
			$requestUid = intval($id);
			$moderate = $fieldArray["moderate"];
			$targetFolder = '';
			
			switch ($moderate) {
				case "0":
					// 31 "not yet reviewed"
					$targetFolder = 31;
					break;
				case "1":
					// 33 "approved"
					$targetFolder = 33;
					break;
				case "2":
					// 32 "rejected"
					$targetFolder = 32;
					break;
			}
			
			$cmd['tx_svgfoobar_request'][$requestUid]['move'] = $targetFolder;
			
			$tce = t3lib_div::makeInstance('t3lib_TCEmain');
			$tce->stripslashes_values=0;
			$tce->start(array(),$cmd);
			$tce->process_cmdmap();
			
		}
	}	

}

if (defined('TYPO3_MODE') && 
$TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/templavoila/class.tx_svgfoobar_tcemain.php']) 
    {
 
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/templavoila/class.tx_svgfoobar_tcemain.php']);
}

?>

Sander van Gelderen schreef:
> Hello list,
> 
> I am trying to make use of the processCmdmap_postProcess hook in class 
> t3lib_TCEmain, but no luck yet.
> 
> I created an extension (key: svgfoobar) with kickstarter, it has two 
> tables and a FE plugin.
> The plugin is not 'Add to Insert Plugin list in Content Elements' as I 
> have used until now, but 'Add as a totally new Content Element type'. 
> This seems to work fine, I get a very nice 'Hello world!' and TypoScript 
> passed to the method is shown correctly.
> 
> The result I am trying to achieve: If a user updates a record from one 
> of my tables in Web>List, the record should be moved to a different 
> sysFolder (depending on the change made to a certain field in the record).
> 
> Here is where I am with it at the moment:
> 
> 1) I have created a class (tx_svgfoobar_tcemain) in the root of my ext 
> folder, it contains the following:
> 
> class tx_svgfoobar_tcemain {
>   function processCmdmap_postProcess($command, $table, $id, $value, 
> &$reference) {
>     t3lib_div::devLog ('processCmdmap_postProcess', 'svgfoobar', 0, 
> array ($command, $table, $id, $value));
>   }
> }
> 
> Only trying to get some debug output for now, I intend to use 
> $tce->process_cmdmap(); for moving the record once I get past this first 
> hurdle. I have cc_devlog installed.
> 
> 2) in my ext localconf.php I add the following lines:
> require_once(t3lib_extMgm::extPath('svgfoobar').'class.tx_svgfoobar_tcemain.php'); 
> 
> $GLOBALS 
> ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass'][] 
> = 'EXT:svgfoobar/class.tx_svgfoobar_tcemain.php:tx_svgfoobar_tcemain';
> 
> I am uncertain that the include_once line is in the correct place?
> 
> 3) in the configuration tool ($TYPO3_CONF_VARS), I can see my class, it 
> is sitting under templavoila   entry (which I am copying from as much as 
> possible)
> 
> 
> The Problem: No output from my class in DevLog, in fact the only entries 
> in there are from t3lib_userAuth.
> 
> Questions:
> 1) Is this the right approach in the first place?
> 2) How can I get it to work?
> 
> 
> TIA,
> 
> Sander


More information about the TYPO3-english mailing list