Search code examples
phptypo3extbasetypo3-6.2.x

How to use Hook "processDatamap_postProcFieldArray" in TYPO3


Use case: When saving an object (in backend, maybe in frontend too later) I want to manipulate values before saving to database.

Problem: The file seems to get included (shows an error on save if I choose a wrong file path) but the function does not seem to be executed on save of the object.

There are many how-tos (most of them T4.5 related) and related questions on stackoverflow but none of them seems to work for me.

Environement: TYPO3 6.2, Extbase

Minimalistic test case:

/ext/navolspmanager/ext_localconf.php

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] =
'EXT:navolspmanager/Classes/Hooks/GetGeoCodesHook.php:\NachVORNE\Navolspmanager\Hooks\GetGeoCodesHook'; 

UPADTED for reference: This last line had to be changed to solve the Problem

/ext/navolspmanager/Classes/Hooks/GetGeoCodesHook.php

<?php
    namespace NachVORNE\Navolspmanager\Hooks;
    class GetGeoCodesHook {
        public function processDatamap_preProcessFieldArray( array $fieldArray, $table, $id, \TYPO3\CMS\Core\DataHandling\DataHandler &$pObj ) {
            if ($table == 'tx_navolspmanager_domain_model_dataset') {
                $fieldArray['geolng'] = 01.001; // for testing purposes
                var_dump($fieldArray); die();
            }
            else{
                var_dump($table); die();
            }
        }
    }

Current status: On save it doesn't crash or show anything, just smoothly saves and ignores this function.

Can anyone show me what I am missing here?


Solution

  • Solved:

    in my ext_localconf.php there was just a '/' missing inside the namespace ...

    $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] =          
    'EXT:navolspmanager/Classes/Hooks/GetGeoCodesHook.php:\NachVORNE\Navolspmanager\Hooks\GetGeoCodesHook';
    

    Improvements:

    When updating one field according to other user input we should use the 'processDatamap_postProcessFieldArray' function. That way trim, date and number stuff etc is already done at the moment we grep the input.