I'm trying to create nested record structures using TYPO3's DataHandler data structures (tested with TYPO3 v7). However relations are not created as expected. Consider the following data structure:
$data = array(
'sys_category' =>
array(
'NEW_1' =>
array(
'title' => 'Category 1',
'pid' => $pid,
),
'NEW_2' =>
array(
'title' => 'Category 3',
'pid' => $pid,
),
'NEW_3' =>
array(
'title' => 'Category 2',
'pid' => $pid,
),
'NEW_4' =>
array(
'title' => 'Category 1.1',
'pid' => $pid,
'parent' => 'NEW_1',
),
'NEW_5' =>
array(
'title' => 'Category 1.2',
'pid' => $pid,
'parent' => 'NEW_1',
),
'NEW_6' =>
array(
'title' => 'Category 3.1',
'pid' => $pid,
'parent' => 'NEW_2',
),
),
);
This gives the following result in the database:
uid title parent
1 Category 1 0
2 Category 3 0
3 Category 2 0
4 Category 1.1 0
5 Category 1.2 0
6 Category 3.1 0
Note the "0" value for all "parent" fields. Why is it that the "NEW_*" values are not interpreted for the "parent" fields set in the data structure?
As mentioned in a comment above, the situation changed between TYPO3 6.2 and 7.6. The difference lies in \TYPO3\CMS\Core\DataHandling\DataHandler::processRemapStack()
. Starting with TYPO3 7.6, it checks if the "NEW*" placeholders contain a low dash (_
). If yes, the placeholder is split on that character and the first part of the string is considered to be the related table name.
This is a change from before, where the low dash had no special meaning. Indeed, the documentation mentions examples using a low dash.
So the above code works fine with just removing the low dash from all the placeholders.