TYPO3 TCA make the 'default' value dynamic

Viewed 1059

The title is rather self explanatory, but what i would like to have is a dynamic default value.

The idea behind it is to get the biggest number from a column in the database and then add one to the result. This result should be saved as the default value.

Lets take for example this code:

$GLOBALS['TCA'][$modelName]['columns']['autojobnumber'] = array(
    'exclude' => true,
    'label' => 'LLL:EXT:path/To/The/LLL:tx_extension_domain_model_job_autojobnumber',
    'config' => [
        'type' => 'input',
        'size' => 10,
        'eval' => 'trim,int',
        'readOnly' =>1,
        'default' => $result,
    ]
);

The SQL looks like this:

$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_extension_domain_model_job');
$getBiggestNumber = $queryBuilder
     ->select('autojobnumber')
     ->from('tx_extension_domain_model_job')
     ->groupBy('autojobnumber')
     ->orderBy('autojobnumber', 'DESC')
     ->setMaxResults(1)
     ->execute()
     ->fetchColumn(0);
$result = $getBiggestNumber + 1;

So how can i do that "clean"?

I thought about processCmdmap_preProcess but i dont know how to pass the value to the coorisponding TCA field. Plus i do not get any results on my backend when i use the DebuggerUtility like i get them when i use processDatamap_afterAllOperations after saving the Object.

Can someone point me to the right direction?

0 Answers
Related