[BUGFIX] Fetch correct recordTypeValue for group fields 34/43734/5
authorFrans Saris <franssaris@gmail.com>
Fri, 2 Oct 2015 09:44:24 +0000 (11:44 +0200)
committerMorton Jonuschat <m.jonuschat@mojocode.de>
Sat, 3 Oct 2015 08:46:04 +0000 (10:46 +0200)
Change-Id: I4609e84720339818b3a978c864c00b3fc516bcf5
Resolves: #70301
Releases: master
Reviewed-on: http://review.typo3.org/43734
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
typo3/sysext/backend/Classes/Form/FormDataProvider/DatabaseRecordTypeValue.php
typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/DatabaseRecordTypeValueTest.php
typo3/sysext/core/Configuration/DefaultConfiguration.php

index 60116e5..5506b3f 100644 (file)
@@ -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]) {
index c51e157..bf82759 100644 (file)
@@ -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));
+       }
 }
index ddf983b..661e1a6 100644 (file)
@@ -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(