Commit 19e30354 authored by Jan Helke's avatar Jan Helke Committed by Christian Kuhn
Browse files

[TASK] Move rendering of formattedLabel_userFunc to DataProvider

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: default avatarMorton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: default avatarMorton Jonuschat <m.jonuschat@mojocode.de>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 175a7f5c
......@@ -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'];
......
......@@ -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'],
......
......@@ -88,6 +88,32 @@ class TcaRecordTitleTest extends UnitTestCase
$this->assertSame($expected, $this->subject->addData($input));
}
/**
* @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
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment