diff --git a/typo3/sysext/backend/Classes/Form/FormDataProvider/DatabaseRowInitializeNew.php b/typo3/sysext/backend/Classes/Form/FormDataProvider/DatabaseRowInitializeNew.php index 4ce2c47e6a73c2332ad3f49d523884adaeeb69ed..80f3f4149893e767b9da3bb4055fe3788fcbbec6 100644 --- a/typo3/sysext/backend/Classes/Form/FormDataProvider/DatabaseRowInitializeNew.php +++ b/typo3/sysext/backend/Classes/Form/FormDataProvider/DatabaseRowInitializeNew.php @@ -49,6 +49,7 @@ class DatabaseRowInitializeNew implements FormDataProviderInterface $result = $this->setDefaultsFromDefaultValues($result); $result = $this->setDefaultsFromInlineRelations($result); $result = $this->setDefaultsFromInlineParentLanguage($result); + $result = $this->setDefaultsFromInlineParentUid($result); $result = $this->setPid($result); return $result; @@ -223,6 +224,24 @@ class DatabaseRowInitializeNew implements FormDataProviderInterface return $result; } + /** + * Set the parent uid of inline relations created via ajax to the corresponding foreign field + * + * @param array $result Result array + * @return array + */ + protected function setDefaultsFromInlineParentUid(array $result): array + { + $isInlineChild = $result['isInlineChild'] ?? false; + $parentField = $result['inlineParentConfig']['foreign_field'] ?? false; + + if ($isInlineChild && $parentField && !empty($result['inlineParentUid'])) { + $result['databaseRow'][$parentField] = $result['inlineParentUid']; + } + + return $result; + } + /** * Set the pid. This is either the vanillaUid (see description in FormDataCompiler), * or a pid given by pageTsConfig for inline children. diff --git a/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/DatabaseRowInitializeNewTest.php b/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/DatabaseRowInitializeNewTest.php index 0fcb379a14507fcfc8d0c24d9994b4b8b8cefc08..3c47a36d37d2ce2b0ab2f35a0c11aac0508e26f6 100644 --- a/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/DatabaseRowInitializeNewTest.php +++ b/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/DatabaseRowInitializeNewTest.php @@ -709,4 +709,28 @@ class DatabaseRowInitializeNewTest extends UnitTestCase $expected['databaseRow']['pid'] = 42; self::assertSame($expected, (new DatabaseRowInitializeNew)->addData($input)); } + + /** + * @test + */ + public function addDataSetsUidOfParentFieldIfRecordIsInlineChild() + { + $input = [ + 'command' => 'new', + 'tableName' => 'aTable', + 'vanillaUid' => 23, + 'neighborRow' => null, + 'inlineChildChildUid' => null, + 'databaseRow' => [], + 'isInlineChild' => true, + 'inlineParentUid' => 42, + 'inlineParentConfig' => [ + 'foreign_field' => 'theParentField' + ], + ]; + $expected = $input; + $expected['databaseRow']['theParentField'] = 42; + $expected['databaseRow']['pid'] = 23; + self::assertSame($expected, (new DatabaseRowInitializeNew)->addData($input)); + } }