[TASK] Move rendering of formattedLabel_userFunc to DataProvider 77/44377/5
authorJan Helke <typo3@helke.de>
Thu, 29 Oct 2015 20:40:19 +0000 (21:40 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 31 Oct 2015 19:24:08 +0000 (20:24 +0100)
To streamline the FormEngine, the rendering of the
formattedLabel_userFunc is moved to the TcaRecordTitle DataProvider

Resolves: #71144
Releases: master
Change-Id: Ia30c6d3c755e797d72ff6de732fd132b093cbfae
Reviewed-on: https://review.typo3.org/44377
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Form/Container/InlineRecordContainer.php
typo3/sysext/backend/Classes/Form/FormDataProvider/TcaRecordTitle.php
typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaRecordTitleTest.php

index 808322e..498702e 100644 (file)
@@ -309,24 +309,7 @@ class InlineRecordContainer extends AbstractContainer
         // Get the record title/label for a record:
         // Try using a self-defined user function only for formatted labels
         if (isset($GLOBALS['TCA'][$foreign_table]['ctrl']['formattedLabel_userFunc'])) {
-            $params = array(
-                'table' => $foreign_table,
-                'row' => $rec,
-                'title' => '',
-                'isOnSymmetricSide' => $data['isOnSymmetricSide'],
-                'options' => isset($GLOBALS['TCA'][$foreign_table]['ctrl']['formattedLabel_userFunc_options'])
-                    ? $GLOBALS['TCA'][$foreign_table]['ctrl']['formattedLabel_userFunc_options']
-                    : array(),
-                'parent' => array(
-                    'uid' => $parentUid,
-                    'config' => $config
-                )
-            );
-            // callUserFunction requires a third parameter, but we don't want to give $this as reference!
-            $null = null;
-            GeneralUtility::callUserFunction($GLOBALS['TCA'][$foreign_table]['ctrl']['formattedLabel_userFunc'], $params, $null);
-            $recTitle = $params['title'];
-
+            $recTitle = $data['recordTitle'];
             // Try using a normal self-defined user function
         } elseif (isset($GLOBALS['TCA'][$foreign_table]['ctrl']['label_userFunc'])) {
             $recTitle = $data['recordTitle'];
index 3a1c165..4cd498c 100644 (file)
@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Backend\Form\FormDataProvider;
 use TYPO3\CMS\Backend\Form\FormDataProviderInterface;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Database\DatabaseConnection;
+use TYPO3\CMS\Core\Database\RelationHandler;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Lang\LanguageService;
 
@@ -43,7 +44,25 @@ class TcaRecordTitle implements FormDataProviderInterface
             );
         }
 
-        if (isset($result['processedTca']['ctrl']['label_userFunc'])) {
+        if ($result['isInlineChild'] && isset($result['processedTca']['ctrl']['formattedLabel_userFunc'])) {
+            $parameters = [
+                'table' => $result['tableName'],
+                'row' => $result['databaseRow'],
+                'title' => '',
+                'isOnSymmetricSide' => $result['isOnSymmetricSide'],
+                'options' => isset($result['processedTca']['ctrl']['formattedLabel_userFunc_options'])
+                    ? $result['processedTca']['ctrl']['formattedLabel_userFunc_options']
+                    : [],
+                'parent' => [
+                    'uid' => $result['databaseRow']['uid'],
+                    'config' => $result['inlineParentConfig']
+                ]
+            ];
+            // callUserFunction requires a third parameter, but we don't want to give $this as reference!
+            $null = null;
+            GeneralUtility::callUserFunction($result['processedTca']['ctrl']['formattedLabel_userFunc'], $parameters, $null);
+            $result['recordTitle'] = $parameters['title'];
+        } elseif (isset($result['processedTca']['ctrl']['label_userFunc'])) {
             // userFunc takes precedence over everything
             $parameters = [
                 'table' => $result['tableName'],
index fae15aa..89b0100 100644 (file)
@@ -91,6 +91,32 @@ class TcaRecordTitleTest extends UnitTestCase
     /**
      * @test
      */
+    public function addDataReturnsRecordTitleForFormattedLabelUserFunction()
+    {
+        $input = [
+            'tableName' => 'aTable',
+            'databaseRow' => [],
+            'isInlineChild' => true,
+            'processedTca' => [
+                'ctrl' => [
+                    'label' => 'uid',
+                    'formattedLabel_userFunc' => function (&$parameters) {
+                        $parameters['title'] = 'Test';
+                    }
+                ],
+                'columns' => [],
+            ],
+        ];
+
+        $expected = $input;
+        $expected['recordTitle'] = 'Test';
+
+        $this->assertSame($expected, $this->subject->addData($input));
+    }
+
+    /**
+     * @test
+     */
     public function addDataReturnsRecordTitleForUid()
     {
         $input = [