diff --git a/typo3/sysext/backend/Classes/Form/FormDataProvider/DatabaseRecordTypeValue.php b/typo3/sysext/backend/Classes/Form/FormDataProvider/DatabaseRecordTypeValue.php index 60116e5c5f4b7cdea93c4357b587cb43ffa901a4..5506b3f5bf6d8521ec683b00bca42fc09388a837 100644 --- a/typo3/sysext/backend/Classes/Form/FormDataProvider/DatabaseRecordTypeValue.php +++ b/typo3/sysext/backend/Classes/Form/FormDataProvider/DatabaseRecordTypeValue.php @@ -16,6 +16,7 @@ namespace TYPO3\CMS\Backend\Form\FormDataProvider; use TYPO3\CMS\Backend\Form\FormDataProviderInterface; use TYPO3\CMS\Backend\Utility\BackendUtility; +use TYPO3\CMS\Core\Utility\MathUtility; /** * Determine the final TCA type value @@ -91,6 +92,12 @@ class DatabaseRecordTypeValue implements FormDataProviderInterface { 1438253614 ); } + // Extract UID from value formed like {table_name}_{uid}|{default_value} + // @todo: This needs adaption as soon as the group format is changed + if (!MathUtility::canBeInterpretedAsInteger($foreignUid)) { + list($foreignUid) = explode('|', $foreignUid); + $foreignUid = str_replace($foreignTable . '_', '', $foreignUid); + } // Fetch field of this foreign row from db $foreignRow = BackendUtility::getRecord($foreignTable, $foreignUid, $foreignTableTypeField); if ($foreignRow[$foreignTableTypeField]) { diff --git a/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/DatabaseRecordTypeValueTest.php b/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/DatabaseRecordTypeValueTest.php index c51e157ef452d070f09810f888834dfa2115cf0b..bf827596e38d9d1232eac49cd28ab1b46d7454aa 100644 --- a/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/DatabaseRecordTypeValueTest.php +++ b/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/DatabaseRecordTypeValueTest.php @@ -409,4 +409,49 @@ class DatabaseRecordTypeValueTest extends UnitTestCase { $this->assertSame($expected, $this->subject->addData($input)); } + + /** + * @test + */ + public function addDataSetsTypeValueFromNestedTcaGroupField() { + $input = [ + 'vanillaTableTca' => [ + 'ctrl' => [ + 'type' => 'uid_local:type', + ], + 'columns' => [ + 'uid_local' => [ + 'config' => [ + 'type' => 'group', + 'internal_type' => 'db', + 'size' => 1, + 'maxitems' => 1, + 'minitems' => 0, + 'allowed' => 'sys_file' + ], + ], + ], + 'types' => [ + '2' => 'foo', + ], + ], + 'databaseRow' => [ + // Processed group field + 'uid_local' => 'sys_file_222|my_test.jpg', + ], + ]; + + $foreignRecordResult = [ + 'type' => 2, + ]; + // Required for BackendUtility::getRecord + $GLOBALS['TCA']['sys_file'] = array('foo'); + + $this->dbProphecy->exec_SELECTgetSingleRow('type', 'sys_file', 'uid=222')->shouldBeCalled()->willReturn($foreignRecordResult); + + $expected = $input; + $expected['recordTypeValue'] = '2'; + + $this->assertSame($expected, $this->subject->addData($input)); + } } diff --git a/typo3/sysext/core/Configuration/DefaultConfiguration.php b/typo3/sysext/core/Configuration/DefaultConfiguration.php index ddf983bd1e12f6d0c99bf17b5286f622ba340319..661e1a6fe02dd7061d5094bd2847bce4e323fc0b 100644 --- a/typo3/sysext/core/Configuration/DefaultConfiguration.php +++ b/typo3/sysext/core/Configuration/DefaultConfiguration.php @@ -386,6 +386,8 @@ return array( \TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRecordTypeValue::class => array( 'depends' => array( \TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseLanguageRows::class, + // As the ctrl.type can hold a nested key we need to resolve all relations + \TYPO3\CMS\Backend\Form\FormDataProvider\TcaGroup::class, ), ), \TYPO3\CMS\Backend\Form\FormDataProvider\PageTsConfigMerged::class => array(