[BUGFIX] FormEngine: formattedLabel_userFunc_options overrides foreign_label 78/44978/3
authorMorton Jonuschat <m.jonuschat@mojocode.de>
Fri, 27 Nov 2015 13:28:37 +0000 (14:28 +0100)
committerGeorg Ringer <georg.ringer@gmail.com>
Sat, 28 Nov 2015 19:47:06 +0000 (20:47 +0100)
Change the order in which the record title for inline records is
determined. As with normal records the userFunc should override the
plain label. Inline records use the special formattedLabel_userFunc
instead of a normal userFunc.

Resolves: #71879
Releases: master
Change-Id: Iaa04530535c109c010f92ac85f8c95952538d2ae
Reviewed-on: https://review.typo3.org/44978
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/backend/Classes/Form/FormDataProvider/TcaRecordTitle.php
typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaRecordTitleTest.php

index 5496196..e5c1a0f 100644 (file)
@@ -43,18 +43,7 @@ class TcaRecordTitle implements FormDataProviderInterface
             );
         }
 
-        if ($result['isInlineChild'] && (isset($result['inlineParentConfig']['foreign_label'])
-                                         || isset($result['inlineParentConfig']['symmetric_label']))
-        ) {
-            // inline child with foreign label or symmetric inline child with symmetric_label
-            $fieldName = $result['isOnSymmetricSide']
-                ? $result['inlineParentConfig']['symmetric_label']
-                : $result['inlineParentConfig']['foreign_label'];
-            // @todo: this is a mixup here. problem is the prep method cuts the string, but also hsc's the thing.
-            // @todo: this is uncool for the userfuncs, so it is applied only here. however, the OuterWrapContainer
-            // @todo: also prep()'s the title created by the else patch below ... find a better separation and clean this up!
-            $result['recordTitle'] = BackendUtility::getRecordTitlePrep($this->getRecordTitleForField($fieldName, $result));
-        } elseif ($result['isInlineChild'] && isset($result['processedTca']['ctrl']['formattedLabel_userFunc'])) {
+        if ($result['isInlineChild'] && isset($result['processedTca']['ctrl']['formattedLabel_userFunc'])) {
             // inline child with formatted user func is first
             $parameters = [
                 'table' => $result['tableName'],
@@ -73,6 +62,17 @@ class TcaRecordTitle implements FormDataProviderInterface
             $null = null;
             GeneralUtility::callUserFunction($result['processedTca']['ctrl']['formattedLabel_userFunc'], $parameters, $null);
             $result['recordTitle'] = $parameters['title'];
+        } elseif ($result['isInlineChild'] && (isset($result['inlineParentConfig']['foreign_label'])
+                || isset($result['inlineParentConfig']['symmetric_label']))
+        ) {
+            // inline child with foreign label or symmetric inline child with symmetric_label
+            $fieldName = $result['isOnSymmetricSide']
+                ? $result['inlineParentConfig']['symmetric_label']
+                : $result['inlineParentConfig']['foreign_label'];
+            // @todo: this is a mixup here. problem is the prep method cuts the string, but also hsc's the thing.
+            // @todo: this is uncool for the userfuncs, so it is applied only here. however, the OuterWrapContainer
+            // @todo: also prep()'s the title created by the else patch below ... find a better separation and clean this up!
+            $result['recordTitle'] = BackendUtility::getRecordTitlePrep($this->getRecordTitleForField($fieldName, $result));
         } elseif (isset($result['processedTca']['ctrl']['label_userFunc'])) {
             // userFunc takes precedence over everything else
             $parameters = [
index 4f1c002..4a04aca 100644 (file)
@@ -152,6 +152,41 @@ class TcaRecordTitleTest extends UnitTestCase
     /**
      * @test
      */
+    public function addDataOverridesRecordTitleWithFormattedLabelUserFuncForInlineChildWithForeignLabel()
+    {
+        $input = [
+            'tableName' => 'aTable',
+            'databaseRow' => [
+                'aField' => 'aValue',
+            ],
+            'processedTca' => [
+                'ctrl' => [
+                    'label' => 'foo',
+                    'formattedLabel_userFunc' => function (&$parameters) {
+                        $parameters['title'] = 'aFormattedLabel';
+                    },
+                ],
+                'columns' => [
+                    'aField' => [
+                        'config' => [
+                            'type' => 'input',
+                        ],
+                    ],
+                ],
+            ],
+            'isInlineChild' => true,
+            'inlineParentConfig' => [
+                'foreign_label' => 'aField',
+            ],
+        ];
+        $expected = $input;
+        $expected['recordTitle'] = 'aFormattedLabel';
+        $this->assertSame($expected, $this->subject->addData($input));
+    }
+
+    /**
+     * @test
+     */
     public function addDataReturnsRecordTitleForInlineChildWithSymmetricLabel()
     {
         $input = [