Discussion:
[TYPO3-english] Hooks: processDatamap_preProcessFieldArray()
Christian Tauscher
2017-08-08 11:11:17 UTC
Permalink
Hello dear Developers

I am about porting an Extention from T3-6.2 to T3-7.6+


in the original EXT I have used a Hook in case a record is copied the
increase some value:

function processDatamap_preProcessFieldArray(
&$fieldArray, $table, $id, &$reference
) {
// make sure only my table in handeled
if($table != "tx_myext_table") return;

// t3_origuid is set? Yes, ist a Copy
if(isset($fieldArray['t3_origuid'])) {
$fieldArray['field1']++;
$fieldArray['filed2']--;
}
}


I translated this to this 7.6 Hook-Call

public function processDatamap_preProcessFieldArray(
&$fieldArray, $table, $id,
\TYPO3\CMS\Core\DataHandling\DataHandler &$pObj
) {
// do the same stuff as in 6.2
// BUT...
}



BUT: How can I tell exactly this record is a COPY?
the field 't3_origuid' seems not to be existing anymore.


one try:

if(strpos(key($pObj->datamap['tx_myext_table']), 'NEW') === 0) {
// do the stuff to be done
}

But this seems not to work and a really NEW record would be catched, too....



If you know a hook to use for this case in T3 7.6+ please let me know.




Christian.
Christian Tauscher
2017-08-08 14:22:08 UTC
Permalink
Post by Christian Tauscher
// t3_origuid is set? Yes, ist a Copy
if(isset($fieldArray['t3_origuid'])) {
$fieldArray['field1']++;
$fieldArray['filed2']--;
}
Ages ago I did use the workspace feature t3_origuid, this is set by the
core if its there and explains if-statement.
Post by Christian Tauscher
If you know a better hook to use for this case in T3 7.6+ please let
me know.
Christian.
Vikram Mandal
2017-08-24 06:30:10 UTC
Permalink
Post by Christian Tauscher
if(strpos(key($pObj->datamap['tx_myext_table']), 'NEW') === 0) {
// do the stuff to be done
}
But this seems not to work and a really NEW record would be catched, too....
Recently I was working on similar thing. I saw it as 'NEW12345' ..may
be it is of some use to you.

- Vikram
Jigal van Hemert
2017-09-05 10:15:53 UTC
Permalink
Hi,
Post by Christian Tauscher
BUT: How can I tell exactly this record is a COPY?
the field 't3_origuid' seems not to be existing anymore.
Haven't dug really deep in it, but a COPY is done through
process_cmdmap() in the DataHandler. Using a combination of the hooks
processCmdmap_preProcess and processCmdmap_postProcess plus the
variables $pasteUpdate and $pasteDatamap you can probably detect COPY
commands and change the necessary values in the $pasteDatamap which you
have marked before in $pasteUpdate.
The actual copy is created between these two hooks and the $pasteDatamap
is executed afterwards to update some fields.
--
Jigal van Hemert
TYPO3 CMS Core Team Member

TYPO3 .... inspiring people to share!
Get involved: typo3.org
Loading...