[TYPO3-dev] tcemain + processDatamap_preProcessFieldArray

Ralf Hettinger ng at ralfhettinger.de
Sun Dec 27 03:51:05 CET 2009


Hi!

Am 27.12.2009 01:06 schrieb Christian Tauscher:

[...]

> I need a call-by-reference:
> 
>> $hookObj->processDatamap_preProcessFieldArray(&$incomingFieldArray,
> $table, $id, $this);
>  
> How can I change Data before it is written to DB?

Declaring the var $incomingFieldArray with a & in your hook function
should do this trick, no?

function processDatamap_preProcessFieldArray(
  &$incomingFieldArray, $table, $id, $callingTCEMAIN
) {
  // ...
  $incomingFieldArray['yourfield'] = 'my override value...';
  // => incomingFieldArray of calling tcemain object is changed ...
  // watch out of tcemain's checks afterwards or use another hook ;)
}


> This works, but how can I Limit this hook only to be called inside *my*
> module? List-Module should not be touched.

Is it limited to certain table / id / tcemain instance? Then a simple if
clause should do.

If you are instantiating the list module from within your own module
(... sounds interesting :) ), you should have typically
$GLOBALS['MCONF'] defined to some specific values of your module and
could condition that. Or (not very nice) if your still using tceFORMs
you could hook up in class t3lib_TCEforms and pass over some specific
inputs...


> Same should be If a realy New (not a copy) record is created, the hook
> should not be called.

It's pretty easy to detect if a record is a "new" record, since the
passed id value ind hook processDatamap_preProcessFieldArray will not be
an int... the following is just an idea, which is far away from perfect,
but should give you an idea...
... like

class tx_myownhookclass_tcemain {
 $this->isNewRecord = false;

 function processDatamap_preProcessFieldArray(
  &$incomingFieldArray, $table, $id, $tcemain
 ) {
   if (!is_int($id)) { // no int value... new record (not bulletproof)
     $this->isNewRecords = false;
   }
 }
 function processDatamap_afterDatabaseOperations(
  $status, $table, $id, $fieldArray, $tcemain
 ) {
   if ($this->isNewRecord) {
     $new_id = $tcemain->substNEWwithIDs[$id];
   }
 }
}


> I hove everybody is clear what I am trying, and someone can help me.

Not that clear admittedly. Hope I could help a bit nevertheless :)


Cheers
Ralf




More information about the TYPO3-dev mailing list