1

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?

  • In `\TYPO3\CMS\Core\DataHandling\DataHandler::checkValueForGroupSelect()` the field value is checked for "NEW" and replacements are mapped. Can you check if something goes horribly wrong there? – Jigal van Hemert Mar 29 '17 at 18:52
  • Seems to be the right place where to look at. The code works in TYPO3 6.2. Will try to dig into that. – François Suter Mar 30 '17 at 10:33

2 Answers2

1

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.

  • For the sake of completeness, this is the related commit: https://review.typo3.org/#/c/49352/ The change went undocumented, although it opens up new possibilities for DataHandler structures. – François Suter Mar 31 '17 at 12:58
0

As far as I see only the pid-value is checked for the "NEW"-keyword. But you could use some of the included hooks for enabling the assignment for "parent" too.

EDIT: I'm referring to TYPO3\CMS\Core\DataHandling\DataHandler::process_datamap()

David
  • 5,882
  • 3
  • 33
  • 44
  • There's indeed something special about the "pid" field. But others are supposed to be checked too, as Jigal mentioned in his replay. – François Suter Mar 30 '17 at 10:34
  • Nice, that you got it solved. Hooks would make it difficult perhaps too, depending on the available data inside the hook-calls, they might be too limited. – David Mar 31 '17 at 10:59